JQGrid:根据内容动态地将单元格设置为不可编辑

JQGrid: Dynamically set a cell to uneditable based on content(JQGrid:根据内容动态地将单元格设置为不可编辑)

本文介绍了JQGrid:根据内容动态地将单元格设置为不可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使列设置为可编辑,我在使某些单元格(使用 cellEdit: true)不可编辑时也遇到了一些问题.

I'm having some issues getting some cells (with cell true) to be non-editable even though the column is set to editable.

我尝试了很多方法,例如 beforeEditCell、格式化程序等.似乎都没有.

I've tried many ways, like beforeEditCell, formatters, etc. None seem to work.

我最接近的方法是将格式化程序设置为我希望可编辑的列,然后使用 setCell 设置不可编辑单元格"类(下面的片段).第一次单击单元格时,不幸的是它进入了编辑模式,但如果您单击其他地方并尝试重新编辑单元格,则成功无法编辑.

The closest I've got is by setting a formatter to the column that I'd like to be editable and then using setCell to set the 'not-editable-cell' class (snippet below). The first time you click the cell, it unfortunately goes into edit mode, but if you click elsewhere and try to re-edit the cell, it's successfully uneditable.

我也尝试在 beforeEditCell 内部使用相同的剪辑,它成功地阻止了单元格被编辑,但反过来冻结"了网格.您不能再选择任何其他单元格.

I've also tried using the same snipped but inside of beforeEditCell, it successfully stops the cell from being edited but in turn 'freezes' the grid. You can no longer select any other cell.

function noEditFormatter(cellValue, options, rowObject) {
    if (cellValue == 'test')
        jQuery("#grid").jqGrid('setCell', options.rowId, 'ColName', '', 'not-editable-cell');
    return cellValue;
}

任何帮助将不胜感激.

推荐答案

使用思路setCell 向不应编辑的单元格添加类不可编辑单元格"的方法是正确的.你只选择了错误的地方来做这件事.在自定义格式化程序内部,网格直到最后都无法构建.我建议您使用 loadComplete 或 gridComplete 以检查 当前页面 的网格包含并将某些单元格标记为不可编辑.

The idea to use setCell method to add class 'not-editable-cell' to the cells which should be not-editable is correct. You choose only the wrong place to do this. Inside of custom formatter, the grid can be not yet built till the end. I recommend you to use loadComplete or gridComplete to examine the grid contain of the current page and mark some cells as not-editable.

我准备了 一个示例 来证明这一点.就像在您的示例中一样,所有具有测试"文本的单元格都被标记为不可编辑.通过这种方式,您可以检查一个单元格并将另一个单元格标记为不可编辑.

I prepared an example which demonstrate this. Like in your example all cells having "test" text are marked as non-editable. In the way you can examine one cells and mark another cells as non-editable.

这篇关于JQGrid:根据内容动态地将单元格设置为不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:JQGrid:根据内容动态地将单元格设置为不可编辑

基础教程推荐