Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqGrid-仅编辑可编辑列的某些行_Javascript_Jquery_Jqgrid - Fatal编程技术网

Javascript jqGrid-仅编辑可编辑列的某些行

Javascript jqGrid-仅编辑可编辑列的某些行,javascript,jquery,jqgrid,Javascript,Jquery,Jqgrid,是否可以对标记为可编辑的列中的某些单元格禁用编辑 据我所见,唯一的选项是“所有单元格都可编辑”或“没有单元格可编辑”。 有办法解决这个问题吗?我建议您使用所谓的“内联编辑”进行行编辑。这种方法的最大优点是,它非常直观,而且对用户非常有用。您可以在演示页面上看到它是如何工作的。在此演示中选择“行编辑”,然后在左侧树部分选择“使用事件”或“输入类型”。使用此方法,您可以执行任何自定义验证,以确定所选行是否应允许在事件句柄oncetrow或ondblClickRow中编辑。如果允许编辑,则调用jqGr

是否可以对标记为可编辑的列中的某些单元格禁用编辑

据我所见,唯一的选项是“所有单元格都可编辑”或“没有单元格可编辑”。
有办法解决这个问题吗?

我建议您使用所谓的“内联编辑”进行行编辑。这种方法的最大优点是,它非常直观,而且对用户非常有用。您可以在演示页面上看到它是如何工作的。在此演示中选择“行编辑”,然后在左侧树部分选择“使用事件”或“输入类型”。使用此方法,您可以执行任何自定义验证,以确定所选行是否应允许在事件句柄
oncetrow
ondblClickRow
中编辑。如果允许编辑,则调用jqGrid的
editRow
方法。此方法为所有可编辑列创建输入控件,用户可以自然地修改行值。如果用户按“回车”键或按“esc”键取消,修改将被保存

我个人更喜欢在
ondblClickRow
事件处理程序中实现对
editRow
方法的调用。因此,用户可以像往常一样继续选择行,并可以使用双击进行行编辑。伪代码如下所示:

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创建XML时,为每一行提供一些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);

}
您可以进一步实现自己


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

感谢您的详细输入。听起来是一个合理的解决方案。@Oleg:这仍然允许行的内联和表单编辑。如何防止禁用行的内联和表单编辑?