Reputation: 63
I'm trying to have jqxbuttons enabled/disabled depending on whether my jqxgrid has data to display. The only way I could think of to check whether my jqxgrid is empty or not was to do something like:
function CheckIfGridEmpty()
{
// Retrieve row data from my grid
var rows = $('#myGrid').jqxGrid('getRows');
if (rows.length > 0)
{
console.log("Grid is not empty");
}
else
{
console.log("Grid is empty");
}
}
Is there an easier or better way to do this?
Upvotes: 0
Views: 1139
Reputation: 1555
Your solution is potentially wrong, if you filter the grid. getrows
returns only the rows matching the filter.
getrows
Gets all rows. Returns an array of all rows loaded in the Grid. If the Grid is filtered, the returned value is an array of the filtered records.
You can use getboundrows
instead:
getboundrows
Gets all rows loaded from the data source. The method returns an Array of all rows. The Grid's sorting, filtering, grouping and paging will not affect the result of this method. It will always return the rows collection loaded from the data source.
You could also use $('#myGrid').jqxGrid('source').records.length
. However, I think we cannot say that this is more easy.
Hope this helps!
Upvotes: 1