如何在 jqGrid MVC 版本中动态地使单元格可编辑

How to dynmically make a cell editable in jqGrid MVC version

我想我可以使用事件 gridInitialized 一个 运行 循环遍历每一行的 id 添加 class 'non-editable-cell' 但是添加了 class 但是当行进入编辑模式,带有 class 的单元格仍然可编辑。

function gridInitialized() { var grid = jQuery('#enabledLanguagesGrid'); 
    var ids = grid.getDataIDs(); 
    for(var i = 0; i < ids.length; i++)  
        var id = ids[i]; 
        if (grid.getCell(id, 'isCustom') === 'True') {
            grid.setCell(id, 'name', '', 'not-editable-cell')
        } 
    } 
}

当我使用 grid.editRow 进入编辑模式时,名称字段仍然可以编辑。

另外请注意,我在 trirand.net public 论坛或支持电子邮件地址上没有收到任何回复。距离我第一次接触他们已经8天了。还有其他人在 Trirand 的支持方面遇到问题吗?

非常感谢

请在您的所有问题中包含有关您使用(可以使用)的 jqGrid 版本的信息,以及有关分叉(free jqGrid, commercial Guriddo jqGrid JS 或版本 <=4.7 的旧 jqGrid)的信息。

了解这一点很重要,jqGrid 有 3 种可供选择的编辑模式:内联编辑、表单编辑和单元格编辑。 class not-editable-cell 将仅用于单元格编辑。您写了有关 editRow 的内容,这是内联编辑的一部分。它支持``不可编辑行`class,可以设置以防止整行可编辑。

您的要求的实现在很大程度上取决于您的确切要求和您使用的 jqGrid 版本。如果您使用 free jqGrid fork, which I develop starting with the end of 2014 (after making the main fork commercial and renaming it to Guriddo jqGrid JS). Free jqGrid allows to define editable property of the column as callback function. The feature is described in the wiki article,则存在最简单的解决方案。回调函数以rowid为参数,可以获取该行的数据,分析数据并return true/false(允许或不允许编辑单元格)取决于任何自定义标准。 editable 属性 as 回调在所有编辑模式下实现。

如果您必须使用旧版本的 jqGrid,那么您应该遵循 the old answer or in this one 中描述的解决方案。只有直接调用 editRow 才能轻松实现解决方案。间接使用 editRow(通过 inlineNavformatter: "actions")的解决方案要复杂得多。

最后的评论。您应该尝试 永远不要 使用您发布的 gridInitialized 之类的代码,因为它 修改 循环中页面上的数据。重要的是要理解,在 HTML 页面上修改 一个元素 遵循 web browser reflow. The web browser have to recalculate or to change the position or other properties of all existing elements on the page. Thus you essentially increase the complexity of the code and reduce the performance of your page if you modify elements on the page. I'd recommend you to read the old article 并使用 cellattrrowattr 和自定义格式化程序而不是在循环中更改数据。