我有几个包含jqGrid的页面,所有这些页面都定义了默认的onSelectRowEventHandler函数。
在其中一些页面上,我想放在部分视图(@Html.Partial("SpecialGridScripts");
)中,并在文档就绪处理程序中,将第二个事件处理程序绑定到selectrow。当用户选择一行时,原始事件处理程序和自定义事件处理程序都应该启动。
到目前为止我尝试过的(不起作用):
$(document).ready(function () {
jQuery.extend(jQuery.jgrid.defaults, {
onSelectAll: function (ids, selected) {
$(this).triggerHandler("selectAll.jqGrid", [ids, selected]);
},
onSelectRow: function (id, selected) {
$(this).triggerHandler("selectRow.jqGrid", [id, selected]);
},
});
$('#myGrid').bind('selectRow.jqGrid', function (event, id, selected) {
UpdateVisibility();
});
});
基于此jqgrid多个事件处理程序示例
我自己解决了这个问题:
$(document).ready(function () {
jQuery.extend(jQuery.jgrid.defaults, {
onSelectAll: function (ids, selected) {
$(this).triggerHandler("selectAll.jqGrid", [ids, selected]);
},
onSelectRow: function (id, selected) {
$(this).triggerHandler("selectRow.jqGrid", [id, selected]);
},
});
$('#myGrid').on('jqGridSelectRow jqGridSelectAll', function (event, id, selected) {
UpdateVisibility();
});
});
对于jqGrid版本>4.3.2,它使用jQuery事件,因此我可以将它动态绑定到jqGridSelectRow和jqGridSelectedAll。我认为我发布的链接中的解决方案仅适用于jqGrid<4.3.2版本。