View Full Version : 3.0 Batch save issues/questions

19 Jun 2009, 4:09 AM
Hi all,

1) Regarding the batch save option for a grid, I'd like to always send an array from ext to the server. That would save me a server side check to find out if it's just one or multiple records that need updating:

So instead of

data: {"fieldname":"value","id":1}I'd like:

data: [{"fieldname":"value","id":1}]I really, really like being able to use the batch save feature.
But there are several issues:

2) What is the expected returnvalue from a batch update?
If I send

data: [{"fieldname":"value","id":1},{"fieldname":"value2","id":2}
]and record 1 updates fine, but record 2 causes a business rule violation, should
success be true? i.e.

success: true,
data: [{"fieldname":"updated value","id":1},{"fieldname":"old value","id":2}

Now, the standard onUpdate commits all changes if success=true, and does not commit any change when success=false.

3) How are we returning error values for specific records? Something like:

success: true, // Signals some records were updated succesfully
data: [{"fieldname":"updated value","id":1}], // Successful update returns the data changed
errors: [{
"id": 2,
"fieldname": "The field that caused the error",
"msg": "This field violates a business rule"
}]In the errors structure, the fieldname may be optional, so that we can return a message concerning the whole record:

success: true, // Signals some records were updated succesfully
data: [{"fieldname":"updated value","id":1}], // Successful update returns the data changed
errors: [{
"id": 2,
"msg": "You are not allowed to change this record"
}]4) Is paging already integrated with batch saving?
i.e. what happens when I change some records and then navigate to the next page without saving?
What happens when I close the grid? It would be really nice to have (a plugin) that would ask us if
we want to save the changes...
What happens when there's an error for a record on another page?

5) An undo functionality would be really nice, when using batch save. (Being able to undo the last client side change, before it's saved to the server)
I don't know yet how changes are stored, but if they're stored sequentially,
we could create a button that would undo the last change.

21 Jun 2009, 3:37 AM
Hi all,

I'm trying to get the grid's batch save functionality to work, which is not that hard :) However, returning and visualizing errors for some records in the batch, while saving and returning the (remaining) correctly saved records is a little more complicated.

Below is a grid plugin (work in progress) that can be used in a grid with batch save enabled. Basically, if I send:

data: [{id: 1, fld: "hi"}, {id: 2, fld:""}]

the reader's update expect this json response:

data: [{id: 1, fld: "hi"}, {id: 2, fld:""}]

But I return (Simulating a server side business rule violation for record 2)

data: [{id: 1, fld: "hi"}],
errors: [{id: 2, field:"fld", msg:"server side business rule violation message"}]

So to prevent the reader's update from throwing an exception, I remove record 2 from the original records send (rs). So far, this works, but...:

The design is that all modified records are removed after an update. I'd like to keep these 'changed' records with errors, and provide the user with a reset (/paging toolbar reload) option. But I want to keep the data with errors so a user can modify the error'ed fields without having to retype other fields in that record.

Am I the only one here to want this functionality? Is there a standard way/format to achieve this or am I pioneering here?

Here's the plugin.

Ext.twensoc.GridCrudErrorPlugin = function(config) {
config = config || {};
Ext.apply(this, config);

Ext.twensoc.GridCrudErrorPlugin.prototype = {
init : function(grid){
this.grid = grid;
grid.store.on('write', this.onWrite, this);

onWrite: function(store, action, result, res, rs) {
// rs contains all the records originally send.
// Remove the records with an error from rs,
// so the onUpdate will not find a mismatch between the records send
// and the records successfully saved in the Ext.data.DataReader's update method
Ext.each(res.errors, function(err) {
var o;
for(var i=rs.length-1; i>0; i--) {
o = rs[i];
if(o && err.id == o.id) {
}, this)

// TODO: Visually mark the error fields and prevent
// these records with errors from being removed from
// the modified records list


23 Jun 2009, 11:02 AM
FYI, here's (http://extjs.com/forum/showthread.php?t=72204) the plugin.