-
當某列編輯完成後,需要對目前列所在的行進行修改操作:
$("#grid").bootstrapTable({
url:'',
……
…… //其他屬性
columns:[{
field:'rowId',
title:'序号',
width:30,
align: 'center',
formatter:function(value,row,index){
row.rowId = index;
return index+1;
}
…… //其他列
}],
onEditableSave: function (field, row, oldValue, $el) {
$table = $('#grid').bootstrapTable({});
$table.bootstrapTable('updateRow', {index: row.rowId, row: row});
}
注意:黑色粗體字就是新增的代碼,表示在列編輯完成後,對目前列所在的行進行修改。
index 表示該行所在的索引。由于onEditableSave函數的參數中沒有index,隻能自己特殊處理了。看到在columns屬性中,有一個field:'rowId’就是自己處理的,rowId賦給row。
-
如果你的列中有
formatter:function(value,row,index){} 函數,
在onEditableSave 方法執行完成後,該函數會重新執行,這樣就會把修改後的列的值重新拿到進行處理。