jQuery UI Widgets Forums Grid Put dropdowngrid element into a cell?

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 10 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Put dropdowngrid element into a cell? #47882

    ziyahan
    Participant

    Hi;
    I would like to put this element into a cell. Element is on the the
    url : http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/dropdowngrid.htm?classic

    is possible?

    Thanks in advance.

    Put dropdowngrid element into a cell? #47887

    Dimitar
    Participant

    Hello ziyahan,

    Here is an example on the matter:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <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="../../jqwidgets/jqxgrid.edit.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 () {
                var data = '[{ "Name": "Beate Wilson", "City": "Brussels"}, {"Name": "Andrew Fuller", "City": "Paris"}, {"Name": "Mayumi Murphy", "City": "Washington"}]';
                // prepare the data
                var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'Name', type: 'string' },
                        { name: 'City', type: 'string' }
                    ],
                    localdata: data
                };
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                var name;
    
                $("#jqxgrid").jqxGrid(
                {
                    width: 300,
                    source: dataAdapter,
                    selectionmode: 'singlecell',
                    editable: true,
                    autoheight: true,
                    columns: [
                        {
                            text: 'Name', datafield: 'Name', width: 150, columntype: 'template',
                            createeditor: function (row, cellvalue, editor, celltext, cellwidth, cellheight) {
                                editor.append('<div style="border-color: transparent;" id="jqxgrid-editor"></div>');
                                editor.jqxDropDownButton({ width: 150, height: 25 });
    
                                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
                                $("#jqxgrid-editor").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-editor").on('rowselect', function (event) {
                                    var args = event.args;
                                    var row = $("#jqxgrid-editor").jqxGrid('getrowdata', args.rowindex);
                                    var dropDownContent = '<div style="position: relative; margin-left: 3px; margin-top: 5px;">' + row['firstname'] + ' ' + row['lastname'] + '</div>';
                                    name = row.firstname + " " + row.lastname;
                                    editor.jqxDropDownButton('setContent', dropDownContent);
                                    editor.css("display", "none");
                                });
    
                                $("#jqxgrid-editor").jqxGrid('selectrow', 0);
                            },
                            geteditorvalue: function (row, cellvalue, editor) {
                                // return the editor's value.
                                editor.jqxDropDownButton("close");
                                return name;
                            }
                        },
                        {
                            text: 'City', datafield: 'City', width: 150
                        }
                    ]
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget'>
            <div id="jqxgrid">
            </div>
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.