jQuery UI Widgets Forums Grid DropDown Grid Sample – can you auto-close the grid after user selects an item?

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  pquimby 10 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • pquimby
    Participant

    Hello–

    I’ve implemented the sample code using the DropDown Grid. I’ve ensured that the user can only select a single item, but the grid continues to remain open until the user clicks somewhere outside the bounds of the grid.

    Is it possible to automatically close the grid after a user selects an item? This way, the DropDown Grid would behave more like a standard dropdown list.

    Thanks,

    Pam


    Peter Stoev
    Keymaster

    Hi Pam,

    To automatically close the DropDown Grid, do the following:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title id='Description'>In this demo, the Grid is used in a combination with the jqxDropDownButton
    widget.</title>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.columnsresize.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownbutton.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.pager.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="../../scripts/demos.js"></script>
    <script type="text/javascript" src="generatedata.js"></script>
    <script type="text/javascript">
    $(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);
    // initialize jqxGrid
    $("#jqxdropdownbutton").jqxDropDownButton({ width: 150, height: 25});
    $("#jqxgrid").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' }
    ]
    });
    $("#jqxgrid").on('rowclick', function (event) {
    $("#jqxdropdownbutton").jqxDropDownButton('close');
    });
    $("#jqxgrid").on('rowselect', function (event) {
    var args = event.args;
    var row = $("#jqxgrid").jqxGrid('getrowdata', args.rowindex);
    var dropDownContent = '<div style="position: relative; margin-left: 3px; margin-top: 5px;">' + row['firstname'] + ' ' + row['lastname'] + '</div>';
    $("#jqxdropdownbutton").jqxDropDownButton('setContent', dropDownContent);
    });
    $("#jqxgrid").jqxGrid('selectrow', 0);
    });
    </script>
    </head>
    <body class='default'>
    <div id='jqxWidget'>
    <div id="jqxdropdownbutton">
    <div style="border-color: transparent;" id="jqxgrid">
    </div>
    </div>
    </div>
    </body>
    </html>

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    pquimby
    Participant

    Perfect! Thanks for the extremely prompt response!!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.