jQuery UI Widgets › Forums › Grid › Using "DropDown Grid" when editing cell in grid
Tagged: Cell, custom, dropdown, dropdown grid, dropdowngrid, editor, grid, jqxgrid
This topic contains 5 replies, has 2 voices, and was last updated by Dimitar 9 years, 12 months ago.
-
Author
-
Hi,
When i use:
{ text: 'Test1', columntype: 'dropdownlist', datafield: 'overrideId', width: 250, createeditor: function (row, column, editor) { var sourceGla = { localdata: dataGla, datatype: "array" }; var dataAdapterGla = new $.jqx.dataAdapter(sourceGla); editor.jqxDropDownList({source: dataAdapterGla, valueMember: "overrideId", renderer: function (index, label, value) { ... } }); }},
grid work well,
Now, i would like to use “DropDown Grid”(not jqxDropDownList) with code:
{ text: 'Product Id', datafield: 'productId', width: 250, createeditor: function (row, column, editor) { var dataAdapterP = new $.jqx.dataAdapter(sourceP); editor.append("<div id='tmpD'></div>"); $(\"#tmpD\").jqxDropDownButton({ width: 150, height: 25}); $("#tmpD").append("<div id='tmpG'></div>"); $("#tmpG").jqxGrid({ width: 550, source: dataAdapterP, pageable: true, autoheight: true, columnsresize: true, columns: [ { text: 'First Name', columntype: 'textbox', datafield: 'firstname', width: 90 }, { text: 'Price', datafield: 'price', cellsalign: 'right', cellsformat: 'c2' } ] }); }}
And it not work, did i make some errors?
Or is there anyway to use it?
Thanks!
Hello Rong Nguyen,
You can find an example of a grid with a dropdown grid cell editor in the following forum post: http://www.jqwidgets.com/community/topic/put-dropdowngrid-element-into-a-cell/#post-47887.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
I have just followed your instruction, but unfortunately, it not work, it show only input text.
I using version 3.3
Please review again your code 🙂
Hi Dimitar,
Sorry for my mistake. Now, it work fine!
Thanks you very much.
Hi Dimitar,
Now, i can display grid, but when i select any row, the buttonDropDown isn’t updated.
I have check event rowselect, it was called for the first time only.
Hi Rong Nguyen,
Here is an updated version of the example, in which rows are selected automatically:
<!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="../../jqwidgets/jqxgrid.filter.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, filterable: 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, filterable: 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); }); }, initeditor: function (row, cellvalue, editor, celltext, pressedChar) { var selected = false; var rows = $('#jqxgrid-editor').jqxGrid('getrows'); var rowsCount = rows.length; for (var i = 0; i < rowsCount; i++) { var firstName = $('#jqxgrid-editor').jqxGrid('getcellvalue', i, "firstname"); var lastName = $('#jqxgrid-editor').jqxGrid('getcellvalue', i, "lastname"); if (cellvalue == (firstName + " " + lastName)) { $('#jqxgrid-editor').jqxGrid('selectrow', i); selected = true; break; }; }; if (selected == false) { $('#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,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.