Get jqGrid object

QuestionsGet jqGrid object
Quang Hoang asked 4 years ago

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

4 Answers
Abu Ghufran Staff answered 4 years ago

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.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Quang Hoang answered 4 years ago

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.

Quang Hoang answered 4 years ago

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)’);
});

Abu Ghufran Staff answered 4 years ago

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

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

7 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?