Hey all,
ExtJS is proving very useful and powerful so far, but I've hit a hitch.
I have a page with an EditorGridPanel connected to a Store, which is populated by JSON generated by a CGI Ajax call, implemented using Ext.data.JsonReader. That much works perfectly, and the contents of a database table are displayed in the grid, and can be edited.
The problem comes with updating the database with changes: as records can be added, modified or deleted on this page, and the amount of data being handled is relatively small, I want to implement the database update as a single AJAX call (?) that sends the entire contents of the grid/store in a POST request, triggered by a save button.
I've had a good look at the API docos for the [Editor]GridPanel and Store classes, and haven't found a way to extract the data in the Store as an array structure or JSON: am I missing something, or is this simply not the right approach?
Here's the code, cut down as much as possible to retain functionality (except the save button).
Code:
var grid = new Ext.grid.EditorGridPanel({
store: store,
cm: cm,
renderTo: 'edit',
width: 620,
height: 300,
title: panel_title,
selModel: new Ext.grid.RowSelectionModel(),
frame: true,
clicksToEdit: 1,
tbar: [{
text: 'Add',
handler : function(){
var p = new simple_record({
title: '',
description: '',
user_id: '',
});
grid.stopEditing();
store.insert(0, p);
grid.startEditing(0, 0);
},
iconCls: 'add',
tooltip: 'Click to add a new record'
}, '-', {
text: 'Delete',
handler : function(){
grid.stopEditing();
store.remove(grid.getSelectionModel().getSelected());
grid.startEditing(0, 0);
},
iconCls: 'remove',
tooltip: 'Click to delete the selected record'
}],
buttons: [{
text: 'Save',
id: 'submit',
handler: function(){
// Send data now
store.commitChanges();
var conn = new Ext.data.Connection();
conn.extraParams = {
task: 'update',
table: simple_table,
data: ??// JSON here
}
conn.request({
url:'cgi-bin/simple_edit.cgi',
method:'POST',
});
}
}]
});
Thanks for any replies.