grid修改后数据保存问题

最近在研究ext grid数据保存,发现有个问题始终想不通。ext.grid 获取到修改的数据如何区分修改的数据操作类型。如:新增的记录、修改的记录和删除的记录,虽然内获取到grid中的所有字段。但如何知道所有的被修改记录中哪条记录是新增进去的、哪条记录是被修改的、哪条记录是新增后被删除的、哪条记录是在原纪录上被修改的?
以下是部分代码:
var grid = new Ext.grid.EditorGridPanel({
title:'显示内容',
loadMask:true,
store: store,
cm: cm,
sm: sm,
width: 600,
height: 280,
renderTo:'griddiv',
viewConfig:{
columsText:'显示的列',
sortAscText:'升序',
sortDescText:'降序',
forceFit:true
},
tbar: new Ext.Toolbar(['-', {
text: '添加一行',
handler: function(){
var p = new Record({
customersid:'',
customername:'',
operatortime:''
});
grid.stopEditing();
store.insert(0, p);
grid.startEditing(0, 0);
}
}, '-', {
text: '删除一行',
handler: function(){
Ext.Msg.confirm('信息', '确定要删除?', function(btn){
if (btn == 'yes') {
var sm = grid.getSelectionModel();
var selectedRow = sm.getSelected();
store.remove(selectedRow);
}
});
}
}, '-',{
xtype:"button",
text: '保存',
handler: function(){
var m = store.modified.slice(0);
var jsonArray = [];
Ext.each(m, function(item) {
jsonArray.push(item.data);
});
Ext.lib.Ajax.request(
'POST',
'10_03_01.jsp',
{success: function(response){
Ext.Msg.alert('信息', response.responseText, function(){
store.reload();
});
},failure: function(){
Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
}},
'data=' + encodeURIComponent(Ext.encode(jsonArray))
);
}
}])
[b]问题补充:[/b]
afteredit 这个方法我想到过,但是还是没有办法区分删除的数据啊
[b]问题补充:[/b]
用数组的方式我也想过,如果用数组的话,那么对于新增和删除的数据都可以通过数组中的一个标志来实现,这样的话我导出的数据中必须要存在一个PK保证唯一性。那么这样做的话通用性势必会差上不少。不知道EXT框架有没有区分这个数据方法。

难道你修改到时候不需要一个id么?

Store 里面有 getModifiedRecords() : Ext.data.Record[] 这个方法是获得所有修改过的记录

EditorGridPanel有这么个事件

afteredit : ( Object e )
Fires after a cell is edited. The edit event object has the following properties grid - This grid record - The reco...
Fires after a cell is edited. The edit event object has the following properties

* grid - This grid 网格
* record - The record being edited 当前修改的记录
* field - The field name being edited 当前修改的字段
* value - The value being set 修改后的value
* originalValue - The original value for the field, before the edit. 修改前的value
* row - The grid row index 行
* column - The grid column index 列

Listeners will be called with the following arguments:

* e : Object
  An edit event (see above for description)

利用这些就可以了

beforeedit : ( Object e )
Fires before cell editing is triggered. The edit event object has the following properties grid - This grid record ...
Fires before cell editing is triggered. The edit event object has the following properties

* grid - This grid
* record - The record being edited
* field - The field name being edited
* value - The value for the field being edited.
* row - The grid row index
* column - The grid column index
* cancel - Set this to true to cancel the edit or return false from your handler.

Listeners will be called with the following arguments:

* e : Object
  An edit event (see above for description)

你可以再grid上面保存一个数组.用这个数组来保存删除记录的id.到时候更新的时候把这个数组一并提交到后台即可

不论是否是新增记录都不怕啦.反正只要你前面删除了.grid的数组就去掉相应的id即可

多一个主键到value很有必要呀,也费不了多少损失