|
Thursday, 19 May 2011 11:31 |
|
Menggunakan Extjs EditorGridPanel, user dapat melakukan penambahan dan merubah data di dalam data Grid, tapi bagaimana cara menyimpan data tersebut? karena data tidak otomatis di submit ke database server.
Jawabannya membuat event afteredit untuk EditorGridPanel, berikut ini contoh kodenya
var grid = new Ext.grid.EditorGridPanel({
store: store,
cm: cm,
renderTo: 'editor-grid',
width: 600,
height: 300,
...
...
...
...
});
grid.on("afteredit", afterEdit);
function afterEdit(e){
var r = e.record; // the row object
var col = e.field; // the field name
var id = r.get("product_id");
if(col == 'date_created'){
var val = Ext.util.Format.date(e.value, "Y-m-d");
}else{
var val = e.value;
}
Ext.Ajax.request({
url: "", // url(): a qeephp global function
params: "id=" + id + "&col=" + col + '&val=' + val, // send the edited column and new value to background
success: function(res){
if(res.responseText != 'ok'){
alert('update failure');
}
}
});
}
|