jQuery Grid: DropDown Grid

The Grid is used in a combination with the jqxDropDownButton widget.

A live JavaScript/jQuery example of jqxGrid, the jQWidgets Grid component, with its complete source code below. It is one of 139 jqxGrid demos for jQuery.

jqxGrid API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGrid shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxbuttons.js, jqxscrollbar.js, jqxmenu.js, jqxgrid.js, jqxgrid.selection.js, jqxgrid.columnsresize.js, jqxlistbox.js, jqxdropdownbutton.js, jqxgrid.pager.js, jqxdropdownlist.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers), generatedata.js (generatedata(), random sample rows).

script.js

$(document).ready(function () {
    // prepare the data
    var data = generatedata(100);

    var source =
    {
        localdata: data,
        datafields:
        [
            { name: 'firstname', type: 'string' },
            { name: 'lastname', type: 'string' },
            { name: 'productname', type: 'string' },
            { name: 'quantity', type: 'number' },
            { name: 'price', type: 'number' }
        ],
        datatype: "array",
        updaterow: function (rowid, rowdata) {
            // synchronize with the server - send update command   
        }
    };

    var dataAdapter = new $.jqx.dataAdapter(source);

    $("#grid").jqxGrid(
     {
         width: 550,
         source: dataAdapter,
         pageable: true,
         autoheight: true,
         columnsresize: true,
         columns: [
           { text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 90 },
           { text: 'Last Name', datafield: 'lastname', columntype: 'textbox', width: 90 },
           { text: 'Product', columntype: 'dropdownlist', datafield: 'productname', width: 180 },
           { text: 'Quantity', datafield: 'quantity', width: 70, cellsalign: 'right' },
           { text: 'Price', datafield: 'price', cellsalign: 'right', cellsformat: 'c2' }
         ]
     });

    // initialize jqxGrid
    $("#jqxdropdownbutton").jqxDropDownButton({
        width: 150, height: 30
    });

    $("#grid").on('rowselect', function (event) {
        var args = event.args;
        var row = $("#grid").jqxGrid('getrowdata', args.rowindex);
        var dropDownContent = '<div style="position: relative; margin-left: 3px; margin-top: 6px;">' + row['firstname'] + ' ' + row['lastname'] + '</div>';
        $("#jqxdropdownbutton").jqxDropDownButton('setContent', dropDownContent);
    });

    $("#grid").jqxGrid('selectrow', 0);

});

body.html

<div id="jqxWidget">
    <div style="margin-left:100px;" id="jqxdropdownbutton">
        <div style="border-color: transparent;" id="grid">
        </div>
    </div>
</div>

Learn more

More jQuery Grid demos