gridComplete 函数中的 jqGrid 绑定事件
我在 ASP.NET MVC 项目中使用 jqgrid。我正在尝试在 gridComplete 函数中绑定单击事件。然后我想检测单击的单元格是否可编辑。到目前为止,我已经得到了这一点:
gridComplete: function () {
var ids = jQuery("#resources").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++) {
var cl = ids[i];
jQuery('#resources').jqGrid('editRow', cl);
}
$("#resources td").click(function(e) {
...//here I want to check if clicked cell is editable
});
}
如您所见,我正在加载网格后立即准备好行进行编辑。这仅指属性 editable=true 的列。
更新:
解决方案非常简单:
$("#resources td").click(function(e) {
var sClassName = e.target.className;
if (sClassName == "editable") {
//editable cell is clicked
}
});
I'm using jqgrid in my ASP.NET MVC project. I'm trying to bind click event in gridComplete function. Then I want to detect if cell, that was clicked is editable or not. So far I've got this:
gridComplete: function () {
var ids = jQuery("#resources").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++) {
var cl = ids[i];
jQuery('#resources').jqGrid('editRow', cl);
}
$("#resources td").click(function(e) {
...//here I want to check if clicked cell is editable
});
}
as you can see I'm making rows ready for edit right after loading a grid. this refers only to columns with attribute editable=true.
UPDATE:
The solution was very simple:
$("#resources td").click(function(e) {
var sClassName = e.target.className;
if (sClassName == "editable") {
//editable cell is clicked
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全理解你的要求。单击“可编辑”或“不可编辑”单元格时您希望执行哪些其他操作?
不过,我建议您使用 onCellSelect 回调处理程序而不是绑定网格中每个单元格的
click
事件。为了理解每个绑定需要一些网络浏览器资源。您可以只绑定一个单元格的父元素,例如元素(网格本身),而不是将事件绑定到单元格。由于称为事件流的机制,< em>事件传播或事件冒泡未处理的事件将尝试由父元素或父元素的父元素的相同事件处理程序处理,依此类推。事件处理程序接收 事件对象,其中 target 属性有助于检测最初单击的是哪个元素。
代码
因此,您可以使用类似或这样的
来检测当前单击的单元格是否不可编辑。
I don't full understand your requirements. What additional actions you want to do on click of the "editable" or "non-editable" cell?
Nevertheless I would recommend you to use onCellSelect callback handler instead of binding
click
event to every cell of the grid. For understanding every binding required some resources of the web browser. Instead of binding events to cells you can do only one bind to any parent element of cell like the<table>
element (the grid itself). Because of the mechanism known as event flow, event propagation or event bubbling the unhandled events will be tried be handled by the same event handler of the parent element or the parent of the parent and so on. The event handler receive Event object which target property helps to detect which element was originally clicked.So you can use the code like
or this
to detect whether the currently clicked cell was non-editable.