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 - 仅编辑可编辑列的某些行
基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01