jqGrid的 - 编辑只为可编辑的列的某些行jqGrid的 - 编辑只为可编辑的列的某些行(jqG

2019-05-12 10:45发布

是否有可能在禁用编辑jqGrid的某些细胞在列标记为可编辑的?

从我所看到的,唯一的选项是“所有单元都是可编辑”或“否细胞可编辑”。 有没有办法解决呢?

Answer 1:

我会建议你使用,因此命名为“在线编辑”进行编辑的行。 这种方法的最大优点,这是非常直观和用户。 你可以看到它是如何工作的演示页http://trirand.com/blog/jqgrid/jqgrid.html 。 选择在这个演示“行编辑”,然后“使用事件”或“输入型”左边树的一部分。 有了这个方法,你可以实现任何自定义的验证所选的行是否应该被允许进行编辑或不里事件的处理onSelectRowondblClickRow 。 如果允许编辑,然后调用editRow jqGrid的方法。 这种方法对于所有可编辑栏输入创建控件,用户可以以自然的方式修改行值。 如果用户按下“Enter”键或取消了“ESC”键的修改将被保存。

我个人更喜欢落实调用editRow的内部方法ondblClickRow事件处理程序。 因此,用户可以继续像往常一样行的选择,并且可以使用双击该行编辑。 伪代码如下如下因素:

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});


Answer 2:

逻辑上,可做到这一点。 您必须为细胞,有些细胞可编辑,有些则不是一些标准。

我已经实现了它排明智的。

当您创建XML为jqGrid的,给予一定的ID给每个行。

基于这些ID,您就可以使可编辑来使用jqGrid的方法,这些行细胞。

下面是beforeEditCell方法:

beforeEditCell: function(rowid, cellname, value, iRow, iCol) {
   // here identify row based on rowid
   // if the row should not be editable than simply make the cells noneditable using
   editCell(iRow, iCol, false);
   jQuery(gridid).jqGrid("restoreCell",iRow,iCol);

}

您可以进一步实现自己。

希望我的建议能帮助你。 :)



文章来源: jqGrid - edit only certain rows for an editable column