需求:当点击新增的时候,testOne和testTwo列均为可编辑的,修改的时候,只能修改testTwo
var operates = {
getRowIndex: function (target) {
var tr = $(target).closest('tr.datagrid-row');
return parseInt(tr.attr('datagrid-row-index'));
},
addRow:function (index) {
//恢复testOne为可编辑项
var $testOne = $(tableId).datagrid('getColumnOption', 'testOne');
$testOne = {type:'text'};
$(tableId).datagrid('insertRow', {
index: index,
row: {
}
});
$(tableId).datagrid('selectRow', index);
$(tableId).datagrid('beginEdit', index);
}
cancelRow:function (target) {
$(tableId).datagrid('cancelEdit', operates.getRowIndex(target));
},
editRow: function (target) {
//设置testOne为不可编辑项
var $testOne = $(tableId).datagrid('getColumnOption', 'testOne');
$testOne = {};
$(tableId).datagrid('beginEdit', operates.getRowIndex(target));
},
saveRow: function (target) {
$(tableId).datagrid('endEdit', operates.getRowIndex(target));
}
}
function loadDruginfoPresList(tableId){
$(tableId).datagrid({
...
columns:[[
{field:'testOne',title:'testOne',width:50,align:'center',editor:{type:'text'}},
{field:'testTwo',title:'testTwo',width:120,align:'center',editor:{type:'text'}},
{field: 'operate', title: 'operate', width: 100, align: 'center',
formatter:function(value,row,index){
var str="";
if (row.editing) {
str += "保存";
str += "取消 ";
} else {
str += "修改 ";
str += "删除 ";
}
return str;
}
}
]],
onLoadSuccess: function(data){
},
onBeforeEdit:function (index,row) {
row.editing=true;
$(tableId).datagrid('refreshRow',index);
},
onAfterEdit:function (index,row) {
row.editing=false;
$(tableId).datagrid('refreshRow',index);
},
onCancelEdit:function (index,row) {
row.editing=false;
$(tableId).datagrid('refreshRow',index);
}
});
}