jqGrid - edit only certain rows for an editable column(jqGrid - 仅编辑可编辑列的某些行)
问题描述
是否可以在某些单元格的 jqGrid 中禁用编辑在标记为可编辑的列中?
Is it possible to disable editing in jqGrid for certain cells in a column that is marked as editable?
据我所知,唯一的选项是所有单元格都可编辑"或没有单元格可编辑".有没有办法解决这个问题?
From what I've seen, the only options are "all cells are editable" or "no cells are editable". Is there a way to work around this?
推荐答案
我会推荐你使用所谓的内联编辑"来进行行编辑.这种方法的最大优点,就是它非常直观和用户.您可以在演示页面 http://trirand.com/blog/jqgrid/jqgrid 上查看它是如何工作的.html.在此演示中选择行编辑",然后在左侧树部分选择使用事件"或输入类型".使用此方法,您可以在事件句柄 onSelectRow
或 ondblClickRow
内实现任何自定义验证是否应允许编辑所选行.如果允许编辑,则调用 jqGrid 的 editRow
方法.此方法为所有可编辑列创建输入控件,用户可以自然地修改行值.如果用户按下enter"键或取消esc"键,修改将被保存.
I'll recommend you to use so named "Inline Editing" for row editing. The most advantage of this method, that it is very intuitive and the user. You can see how it works on the demo page http://trirand.com/blog/jqgrid/jqgrid.html. Choose on this demo "Row Editing" and then "Using Events" or "Input types" on the left tree part. With this method you can implement any custom verification whether the selected row should be allowed to be edited or not inside of the event handle onSelectRow
or ondblClickRow
. If you allow editing, then you call editRow
method of jqGrid. This method creates input controls for all editable columns and the user can modify the row values in a natural way. The modifications will be saved if the user press "enter" key or canceled on "esc" key.
我个人更喜欢在 ondblClickRow
事件处理程序中实现对 editRow
方法的调用.因此用户可以像往常一样继续选择行,并且可以使用双击进行行编辑.伪代码如下所示:
I personally prefer to implement calling of editRow
method inside of ondblClickRow
event handler. So the user can continue selecting of rows like usual and can use double click for the row editing. The pseudo code will look like folowing:
var lastSel = -1;
var isRowEditable = function (id) {
// implement your criteria here
return true;
};
var grid = jQuery('#list').jqGrid({
// ...
ondblClickRow: function(id, ri, ci) {
if (isRowEditable(id)) {
// edit the row and save it on press "enter" key
grid.jqGrid('editRow',id,true);
}
},
onSelectRow: function(id) {
if (id && id !== lastSel) {
// cancel editing of the previous selected row if it was in editing state.
// jqGrid hold intern savedRow array inside of jqGrid object,
// so it is safe to call restoreRow method with any id parameter
// if jqGrid not in editing state
grid.jqGrid('restoreRow',lastSel);
lastSel = id;
}
},
pager: '#pager'
}).jqGrid('navGrid','#pager',{edit:false});
这篇关于jqGrid - 仅编辑可编辑列的某些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jqGrid - 仅编辑可编辑列的某些行


基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01