需要根据特定值使单个 jqgrid 单元格可编辑
Need to make individual jqgrid cells editable based on a certain value
我有一个 jqGrid,我希望某些单元格可以根据单独的隐藏单元格中的值进行编辑。所以网格中的每一行都没有相同的配置。换句话说,我不希望整个专栏都是可编辑的。
我将下面的代码放在网格的 loadComplete 事件中。我遍历每一行并根据隐藏值 ProductCatIndex.
将 EstimatedCost 和 AverageSalePrice 上的可编辑 属性 设置为 true
var ids = $('#' + jqgrid_id).jqGrid('getDataIDs');
var count = $('#' + jqgrid_id).getGridParam('reccount');
for (var x = 0; x < count; x++) {
var rowId = ids[x];
if (row.ProductCatIndex == 2) {
$('#' + jqgrid_id).jqGrid('setCell', rowId, 'EstimatedCost', '', '', { 'editable': true });
}
else if (row.ProductCatIndex == 3) {
$('#' + jqgrid_id).jqGrid('setCell', rowId, 'AverageSalePrice', '', '', { 'editable': true });
}
}
我单步执行代码并 运行 正确查看了它,但是单元格不可编辑。我在网格级别有 cellEdit: true 但我没有在列上设置可编辑的 属性,因为我试图在上面的代码中动态设置它。任何帮助将不胜感激!
你这样做的方式没有任何效果
我可以推荐其他方法来做到这一点。
如果单元格具有 class 'not-editable-cell',则该单元格不可编辑,而是在 colModel 中设置为可编辑。参见 docs here
这样就可以使用 cellattr 函数,因为它会在创建过程中添加属性。参见 docs here too
将可编辑的 属性 设置为 true 并尝试使用此代码:
colModel : [
...
{ name : 'EstimatedCost', editable : true,...,
cellattr : function( id, val, rawdata, cm, rdata) {
ret = ""
if( parseInt(rdata['ProductCatIndex'],10) !== 2 ) {
ret = " class='not-editable-cell'";
}
return ret;
}
}
对另一个字段执行相同的操作。
我有一个 jqGrid,我希望某些单元格可以根据单独的隐藏单元格中的值进行编辑。所以网格中的每一行都没有相同的配置。换句话说,我不希望整个专栏都是可编辑的。
我将下面的代码放在网格的 loadComplete 事件中。我遍历每一行并根据隐藏值 ProductCatIndex.
将 EstimatedCost 和 AverageSalePrice 上的可编辑 属性 设置为 truevar ids = $('#' + jqgrid_id).jqGrid('getDataIDs');
var count = $('#' + jqgrid_id).getGridParam('reccount');
for (var x = 0; x < count; x++) {
var rowId = ids[x];
if (row.ProductCatIndex == 2) {
$('#' + jqgrid_id).jqGrid('setCell', rowId, 'EstimatedCost', '', '', { 'editable': true });
}
else if (row.ProductCatIndex == 3) {
$('#' + jqgrid_id).jqGrid('setCell', rowId, 'AverageSalePrice', '', '', { 'editable': true });
}
}
我单步执行代码并 运行 正确查看了它,但是单元格不可编辑。我在网格级别有 cellEdit: true 但我没有在列上设置可编辑的 属性,因为我试图在上面的代码中动态设置它。任何帮助将不胜感激!
你这样做的方式没有任何效果
我可以推荐其他方法来做到这一点。
如果单元格具有 class 'not-editable-cell',则该单元格不可编辑,而是在 colModel 中设置为可编辑。参见 docs here
这样就可以使用 cellattr 函数,因为它会在创建过程中添加属性。参见 docs here too
将可编辑的 属性 设置为 true 并尝试使用此代码:
colModel : [
...
{ name : 'EstimatedCost', editable : true,...,
cellattr : function( id, val, rawdata, cm, rdata) {
ret = ""
if( parseInt(rdata['ProductCatIndex'],10) !== 2 ) {
ret = " class='not-editable-cell'";
}
return ret;
}
}
对另一个字段执行相同的操作。