Michael Tolentino Michael Tolentino - 1 year ago 142
jQuery Question

Easier or better way to check if jqxgrid has no data to display(is empty)?

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");
console.log("Grid is empty");

Is there an easier or better way to do this?

Answer Source

Your solution is potentially wrong, if you filter the grid. getrows returns only the rows matching the filter.


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:


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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download