I'm trying to enable and disable custom buttons on a jqgrid, but would enable that button only if the grid is empty and then disable when its not.
Is there a way to test of the grid has data or not?
Thanks.
I'm trying to enable and disable custom buttons on a jqgrid, but would enable that button only if the grid is empty and then disable when its not.
Is there a way to test of the grid has data or not?
Thanks.
You can test to see how many records are in the grid. If there are no rows then the grid is empty:
jQuery('#grid').jqGrid('getGridParam', 'reccount');
See the documentation for reccount:
Readonly property. Determines the exactly number of rows in the grid.
Also, since the default value is 0
you need to make sure you call this function after data has loaded, such as in the loadComplete
event.
From the docs:
reccount integer Readonly property.
Determines the exactly number of rows in the grid. Do not mix this with records parameter. Instead that in most cases they are equal there is a case where this is not true. By example you define rowNum parameter 15, but you return from server records parameter = 20, then the records parameter will be 20, the reccount parameter will be 15, and in the grid you will have 15 records.
In the loadcomplete event you have access to the data object that was bound to the grid and you can check the number of records. There you will also be able to setup your buttons
loadComplete: function(data){
//data.Rows.length or call reccount
},
© 2022 - 2024 — McMap. All rights reserved.