我在PHP包装器类的上下文中使用以下PHP代码(因此对“this”的引用;我用“this”填充了它需要的所有信息),以生成将要使用的JSON对象用于创建jqGrid对象客户端:
$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));
然后,我正在获取输出JSON并使用它在jQuery Ajax回调中生成jqGrid实例,如下所示:
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);
}
}
}
如您所见,我目前正在使用两种不同的方法将相同的事件处理函数分配给三个不同的事件。但是,只有第三个,onCellSelect事件似乎会触发,因为这是触发的事件处理程序的唯一实例。
双击并右键单击网格行不会执行任何操作,但是,正常单击行时会触发onCellSelect事件正文中的console.log。
我起初认为这可能是由于其他委派的点击事件重叠,但是,我没有在jqGrid中的任何地方绑定任何此类事件。
如果需要更多信息,请与我们联系。