jQuery UI Widgets › Forums › Grid › Grid draws 1 row even when there is no records it adds also a cellrenderer
Tagged: javascript grid, jquery grid, jqwidgets grid
This topic contains 1 reply, has 2 voices, and was last updated by Peter Stoev 9 years, 9 months ago.
-
Author
-
July 21, 2015 at 3:05 pm Grid draws 1 row even when there is no records it adds also a cellrenderer #73999
My generator gives – [{“TotalRows”:0,”Rows”:null}] but the cellsrenderer still draws a button, I wonder why it doesn’t writes like there is no records or something like that. Additionally there is a grey filter on the table after I click my custom made filter – could it stay normal and doesn’t change color when the filter is applied?
Thanks for help.
Port of the code
var source = { datatype: "json", type: "POST", datafields: [ { name: 'zlec_id', type: 'string'}, //{ name: 'koord', type: 'string'}, { name: 'priorytet', type: 'string' }, { name: 'zlec_addres', type: 'string' }, { name: 'zlec_z_dnia', type: 'string' }, { name: 'zlec_nr', type: 'string' }, { name: 'zlec_do', type: 'string' }, { name: 'zlec_ogran', type: 'string' }, { name: 'awizacje', type: 'string' }, { name: 'awizacja_na_dzien', type: 'string' }, { name: 'status_zlecenia', type: 'string' }, { name: 'termin_zamkniecia', type: 'string' }, { name: 'tresc', type: 'string' }, { name: 'uwagi', type: 'string' } ], cache: false, url: 'serverfiltering_paging_and_sorting_data.php', filter: function() { // update the grid and send a request to the server. $("#jqxgrid").jqxGrid('updatebounddata', 'filter'); }, sort: function() { // update the grid and send a request to the server. $("#jqxgrid").jqxGrid('updatebounddata', 'sort'); }, root: 'Rows', beforeprocessing: function(data) { if (data != null) { source.totalrecords = data[0].TotalRows; } } }; var btnrender = function(row, columnfield, value, defaulthtml, columnproperties) { return '<div style="position: absolute;left: 50%;top: 50%;-webkit-transform: translate(-50%, -50%);transform: translate(-50%, -50%);"><button onClick="zlecTabAppend('+value+')"> Podgląd zlecenia</button></div>'; } var cellsrenderer = function(row, columnfield, value, defaulthtml, columnproperties) { if (value < 'NORMALNY') { return '<div style="position: absolute;left: 50%;top: 50%;-webkit-transform: translate(-50%, -50%);transform: translate(-50%, -50%); color: #00FFFF;">' + value + '</div>'; } else { return '<div style="position: absolute;left: 50%;top: 50%;-webkit-transform: translate(-50%, -50%);transform: translate(-50%, -50%); color: #008000;">' + value + '</div>'; } } var dataadapter = new $.jqx.dataAdapter(source, { loadError: function(xhr, status, error) { alert(error); }, formatData: function(data) { $.extend(data, $("#form_filter").serialize()); return data; } }); var listSource = [ { label: 'Czynności', value: 'zlec_id', checked: true }, //{ label: 'koord', value: 'koord', checked: true }, { label: 'Priorytet', value: 'priorytet', checked: true }, { label: 'Adres', value: 'zlec_addres', checked: true }, { label: 'Z dnia', value: 'zlec_z_dnia', checked: true }, { label: 'Nr zlecenia', value: 'zlec_nr', checked: true }, { label: 'Do dnia', value: 'zlec_do', checked: true }, { label: 'Ograniczenie', value: 'zlec_ogran', checked: true }, { label: 'Awizacje', value: 'awizacje', checked: true }, { label: 'Awizacje na dzień', value: 'awizacja_na_dzien', checked: true }, { label: 'Status', value: 'status_zlecenia', checked: true }, { label: 'Termin zamkniecia', value: 'termin_zamkniecia', checked: true }, { label: 'Treść', value: 'tresc', checked: false }, { label: 'Uwagi', value: 'uwagi', checked: false } ]; $("#jqxlistbox").jqxListBox({ source: listSource, width: '250px', checkboxes: true }); $("#jqxlistbox").on('checkChange', function(event) { $("#jqxgrid").jqxGrid('beginupdate'); if (event.args.checked) { $("#jqxgrid").jqxGrid('showcolumn', event.args.value); } else { $("#jqxgrid").jqxGrid('hidecolumn', event.args.value); } $("#jqxgrid").jqxGrid('endupdate'); }); //$("#jqxgrid").jqxGrid('autoresizecolumns'); // initialize jqxGrid $("#jqxgrid").jqxGrid({ source: dataadapter, autoheight: true, pageable: true, virtualmode: true, width: '99%', height: '200px', autorowheight: true, autoheight: true, localization: getLocalization('de'), rendergridrows: function(obj) { return obj.data; }, columns: [ { text: 'Czynności', datafield: 'zlec_id',cellsrenderer: btnrender}, //{ text: 'koord', datafield: 'koord' }, { text: 'Priorytet', datafield: 'priorytet', cellsrenderer: cellsrenderer }, { text: 'Adres', datafield: 'zlec_addres' }, { text: 'Z dnia', datafield: 'zlec_z_dnia' }, { text: 'Nr zlecenia', datafield: 'zlec_nr' }, { text: 'Do dnia', datafield: 'zlec_do' }, { text: 'Ograniczenie', datafield: 'zlec_ogran' }, { text: 'Awizacje', datafield: 'awizacje' }, { text: 'Awizacje na dzień', datafield: 'awizacja_na_dzien' }, { text: 'Status', datafield: 'status_zlecenia' }, { text: 'Termin zamkniecia', datafield: 'termin_zamkniecia' }, { text: 'Treść', datafield: 'tresc', hidden: true }, { text: 'Uwagi', datafield: 'uwagi', hidden: true } ] });
July 21, 2015 at 9:33 pm Grid draws 1 row even when there is no records it adds also a cellrenderer #74012Hi kavvson,
If you do not have records in your data source, it will display “No Data To Display” as in this example: http://jsfiddle.net/jqwidgets/ofn3x5h9/
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.