我使用jqgrid来纠正一些信息
我的代码是:
var lastsel;
$("#list4").jqGrid({
datatype: "local",
height: 250,
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, editable:true},
......
{name:'note',index:'note', width:150, editable:true}
],
onSelectRow: function(id)
{
if(id && id!==lastsel)
{
if (lastsel!=undefined)
$('#list4').jqGrid('saveRow',lastsel);
$('#list4').jqGrid('editRow',id,true);
lastsel=id;
}
},
viewrecords: false,
multiselect: false,
caption: "Manipulating Array Data",
editurl:'clientArray',
cellSubmit: 'clientArray'
});
mydata = [
{id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
...
{id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
];
for(var i=0;i<=mydata.length;i++)
jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);
但是在编辑单元格后,我看不到mydata中的任何变化。 如何实现到mydata的实时映射?
答案 0 :(得分:1)
我将此代码用于onSelectRow方法
onSelectRow: function(id)
{
if(id && id!==lastsel)
{
if (lastsel!=undefined)
$('#list4').jqGrid('restoreRow',lastsel);
$('#list4').jqGrid('editRow',id,true,false,false,false,false,function(i)
{
console.log($("#list4").getRowData(i));
mydata[i]=$("#list4").getRowData(i);
});
lastsel=id;
}
}