Javascript 如何在JQGrid的行编辑中禁用某些单元格的编辑?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7723621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable editing for some cells in row editing of JQGrid?
提问by Aditya K
When I click on any row of my Grid, All editable columns become editable.
当我单击网格的任何行时,所有可编辑列都变为可编辑。
I want some of the columns to be editable on each row separately.
我希望某些列可以分别在每一行上进行编辑。
Column 1, Column 2, Column 3
ROW Number 1 - editable, non-editable, non-editable
ROW Number 2 - non-editable, editable, non-editable
ROW Number 3 - editable, non-editable, non-editable
Thanks in Advance
提前致谢
回答by Oleg
If you use inline editing modeand want to decide dynamicallywhich cells of the row will be editable for example based on the contain of the cells you can do this in the way which I described here. You can do this with another method also:
如果您使用内联编辑模式并希望动态决定该行的哪些单元格将是可编辑的,例如基于单元格的包含,您可以按照我在此处描述的方式执行此操作。你也可以用另一种方法来做到这一点:
$(this).jqGrid('setColProp', 'YouColumnName', {editable:false});
So you should just set editable
to false
or true
beforecalling of editRowmethod. In the way you can implement any logic which you want.
所以你应该只设置editable
为false
或true
在调用editRow方法之前。通过这种方式,您可以实现您想要的任何逻辑。
UPDATE:Free jqGridallows to define editable
as callback function. See the wiki article. It allows to make the column editable in some rows and holding non-editable for other rows.
更新:免费 jqGrid允许定义editable
为回调函数。请参阅维基文章。它允许使列在某些行中可编辑,而在其他行中不可编辑。
回答by deb_
I had a similar requirement, just expanding on what Olegalready mentioned in his answer:
我有一个类似的要求,只是扩展了Oleg在他的回答中已经提到的内容:
//get colModel properties
var cm = jQuery("#grid").jqGrid('getColProp','myColumn');
//some condition to enable or disable editing
cm.editable = false;
//always call editRow after changing editable property
jQuery('#grid').jqGrid('editRow', rowId, {});
//set default editable option
cm.editable = true;
Cheers :)
干杯:)