Is there a way to get the jqGrid object after rendered the grid? I need this object for handling events manually.
I tried this, but not working.
jQuery(‘#MyGrid’).jqGrid({
onSelectRow: id=> {
console.log(‘Selected row (id:’+ id +’)’);
},
});
I know I can handle this event by using $[‘js_on_select_row’], but for general purpose which may use other events, eg. afterComplete as listed in http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing .
Please advise,
Quang
You can connect all events using grid options. e.g.
$opt[“afterComplete”] = “function(){ }”;
$opt[“onSelectRow”] = “function(){ }”;
…
$g->set_options($opt);
Using grid object like you do is also correct. Just make sure grid is created when you call this. It should be either in loadComplete event OR on some user triggered event like button click.
Thank you for quick reply. I tried your instructions, only onSelectRow event is working. The $opt[“afterComplete”] not is working. I also try to grab the object after the grid is created, use setTimeout 5 seconds or put the script in the function handling the loadComplete event, but none of them is working.
oh, I figured out why the javascript isn’t work
jQuery(‘#MyGrid’).jqGrid({
onSelectRow: id=> {
console.log(‘Selected row (id:’+ id +’)’);
},
});
After the grid is created, it used another event, jqGridSelectRow.
var grid = jQuery(‘#MyGrid’).jqGrid();
grid.bind(‘jqGridSelectRow’, function(e) {
console.log(‘Selected row (e)’);
});
The afterComplete event is not of grid options. It’s from add or edit dialog options.
so, you can set:
$opt[“add_options”][“afterComplete”] = “function() { }”;
To use grid object in JS: you can see various demo code. e.g.
http://gridphp.com/demo/demos/appearance/footer-row.phps line 245,256