即时将第二个 onSelectRow 处理程序绑定到 jqGrid
Posted
技术标签:
【中文标题】即时将第二个 onSelectRow 处理程序绑定到 jqGrid【英文标题】:Binding 2nd onSelectRow handler to jqGrid on the fly 【发布时间】:2013-02-06 16:30:58 【问题描述】:我有几个包含 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();
);
);
Based on this jqgrid multiple event handlers example
【问题讨论】:
为什么不直接从 onSelectRow 事件中调用第二个操作? 消除依赖。 但是你可以让事件调用每个函数,它们不会相互依赖。我的意思不是在第一个函数内部调用第二个函数,而是在事件处理程序内部。 我只是希望自定义内容与页面完全分离——更易于维护。 【参考方案1】:我自己解决了这个问题:
$(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 和 jqGridSelectAll。我认为我发布的链接中的解决方案仅适用于 jqGrid
【讨论】:
以上是关于即时将第二个 onSelectRow 处理程序绑定到 jqGrid的主要内容,如果未能解决你的问题,请参考以下文章