jqGrid - 仅编辑可编辑列的某些行 [英] jqGrid - edit only certain rows for an editable column

查看:30
本文介绍了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.在此演示中选择行编辑",然后在左侧树部分选择使用事件"或输入类型".使用此方法,您可以在事件句柄 onSelectRowondblClickRow 内实现任何自定义验证是否应允许编辑所选行.如果允许编辑,则调用 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 - 仅编辑可编辑列的某些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆