I am using the following PHP code, within the context of a PHP wrapper class (thus the references to "this"; I have "this" filled out with all information it needs), to generate a JSON object that will be used to create a jqGrid object client-side:
$query_object = new stdClass;
$query_object->url = 'go.php';
$query_object->postData = new stdClass;
foreach($this->vars as $key => $value) {
$query_object->postData->$key = $value;
}
$query_object->postData->action = '__query_listen';
$query_object->caption = (isset($this->properties['title']) ? $this->properties['title'] : $this->app_id);
if (isset($this->properties['collapsible'])) {
$query_object->hidegrid = (bool)$this->properties['collapsible'];
$query_object->hiddengrid = (bool)$this->properties['begin_collapsed'];
}
if (isset($this->properties['movable'])) {
$query_object->sortable = true;
}
$query_object->sortname =$this->properties['initial_sort'];
$query_object->datatype = 'json';
$query_object->mtype = 'POST';
$query_object->colModel = $this->query_fields;
$reader = new stdClass;
$reader->repeatitems = false;
if (isset($this->properties['sub_query'])) {
$sub = new stdClass;
$sub->repeatitems = false;
$reader->subgrid = $sub;
}
$query_object->ondblClickRow = new stdClass;
$query_object->ondblClickRow->arg1 = "rowid";
$query_object->ondblClickRow->arg2 = "iRow";
$query_object->ondblClickRow->arg3 = "iCol";
$query_object->ondblClickRow->arg4 = "e";
$query_object->ondblClickRow->body = "console.log('RowID: ' + rowid + ' -- iRow: ' + iRow + ' -- iCol: ' + iCol + ' -- e: ' + e);";
$query_object->jsonReader = $reader;
$query_object->rowList = array(25,50,100,250,500);
$query_object->rowNum = 25;
$query_object->pager = '#' . $this->tab_id . '_' . $this->app_id . '_pager';
$query_object->viewrecords = true;
$query_object->deepempty = true;
$query_object->shrinkToFit = false;
$query_object->toppager = true;
$query_object->height = 'auto';
$query_object->autowidth = true;
// Printing this as an array because there are to be other things in here as well
print json_encode(array($query_object));
And then, I am picking up the output JSON and using it to generate a jqGrid instance within a jQuery Ajax callback, like so:
function load_callback(tab_id, app_id, content_id) {
return function (data, jqxhr, status) {
jqgrid_id = '#' + tab_id + '_' + app_id + '_table';
grid = $(jqgrid_id, this);
grid.jqGrid(data.query_object);
dblclickhandler = grid.getGridParam('ondblClickRow');
if (dblclickhandler !== undefined) {
grid.jqGrid('setGridParam', {'onRightClickRow' : new Function(dblclickhandler['arg1'], dblclickhandler['arg2'], dblclickhandler['arg3'], dblclickhandler['arg4'], dblclickhandler['body'])});
grid.jqGrid('setGridParam', {'ondblClickRow' : function (rowid, iRow, iCol, e) { console.log('RowID: ' + rowid + ' -- iRow: ' + iRow + ' -- iCol: ' + iCol + ' -- e: ' + e); }});
grid.jqGrid('setGridParam', {'onCellSelect' : new Function(dblclickhandler['arg1'], dblclickhandler['arg2'], dblclickhandler['arg3'], dblclickhandler['arg4'], dblclickhandler['body'])});
console.log(grid.getGridParam('ondblClickRow'));
console.log(grid);
}
}
}
As you can see, I'm currently using two different methods of assigning the same event handler function to three different events. However, only the third, the onCellSelect event fires, it seems, as that is the only instance of the event handler that is triggered.
Double-clicking and right-clicking on the grid rows does nothing, however, the console.log within the body of the onCellSelect event is fired when a row is normal-clicked on.
I at first considered that this may be due to having other delegated click events overlapping, however, I do not have any such events bound anywhere within the jqGrid.
Please let me know if more information is needed.