Reputation: 29427
The question is almost complete in the title: is there any way, using jquery, to find the element that is handled by a jqGrid object?
To be more precise, I wish to call a reload method on the grid, if one is present on the page. I am using the following code
...
success: function (data) {
//Check if there is a jqGrid on the page and if present, reloads its data
var jqGrid = $('.ui-jqgrid');
if ( jqGrid.length ) {
//get the grid id. The actual id object is in the form of "gbox_your_grid_id"
var gridid = "#" + jqGrid.attr('id').substring(5);
//time to reload
$(grid).trigger('reloadGrid');
}
}
but it seems that the reloadGrid method is never called. Any suggestion?
Upvotes: 2
Views: 3859
Reputation: 221997
It's difficult to suggest any test which will be perfect. You can try for example to search for the "gbox": $('div.ui-jqgrid')
- it is a div which contain all components of jqGrid. If $('div.ui-jqgrid').length > 0
then exist at least grid on the page.
You can search for the table
element inside of bdiv:
$('div.ui-jqgrid-bdiv table').length > 1
or even for
if ($('div.ui-jqgrid > div.ui-jqgrid-view > div.ui-jqgrid-bdiv > div > table.ui-jqgrid-btable').length > 1) {
// jqGrid exist
}
(see here for details). Additionally you can test whether such table elements have jqGrid
method:
if ($.isFunction($('div.ui-jqgrid > div.ui-jqgrid-view > div.ui-jqgrid-bdiv > div > table.ui-jqgrid-btable').jqGrid)) {
// jqGrid exist
}
Upvotes: 5
Reputation: 42056
I don't know jqGrid itself but I'm pretty sure looking at what it does that it adds custom classes to style elements, so you can most likely identify which class is of interest to you and then use $('.classname')
to grab all elements.
Upvotes: 1