Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically add an event handler on a JQGrid?

Tags:

jquery

jqgrid

I have a JQGrid that's already been initialized. How can I add an event handler to it? I've tried

grid.setGridParam({
    onSelectRow: function(rowid, status) {
        alert("onSelectRow");
    }
});

but this doesn't do anything (no error, but no alert on select either).


Update

Turns out the code above actually works fine - although as @jitter points out the new API syntax is preferred. My problem was that grid was referring to the wrong object. For some reason in the gridComplete event handler, $(this) does not return a reference to the grid, but $("#" + this.id) does.

// handles the gridComplete event
gridInitialized = function() {
    var grid = $("#" + this.id); 
    grid.jqGrid("setGridParam", { onSelectRow: selectRow });
};
like image 470
Herb Caudill Avatar asked Dec 29 '22 08:12

Herb Caudill


1 Answers

The correct way to do this (+ using the new API syntax) is this. Doesn't need a .trigger("reloadGrid")

grid.jqGrid("setGridParam", {
    onSelectRow: function(rowid, status) {
        alert("onSelectRow");
    }
});
like image 190
jitter Avatar answered Jan 22 '23 18:01

jitter