PDA

View Full Version : updating items in a grid with values from an each loop



Anthony.Hall
16 Feb 2012, 9:08 AM
I want to update a property in each item on my store. In the below code i'm trying to set "Seq". This data is in a grid. But it does not update



var count = 1;
store.each(function(f) {
f.data.Seq = count;

count++;
});

mitchellsimoens
16 Feb 2012, 9:55 AM
I wouldn't change the data object directly, personally would use the set method.

If you are going to change the data object, then before the for loop do a beginEdit() on the model and after the for loop do an endEdit() on the model.

Anthony.Hall
16 Feb 2012, 10:06 AM
oh i see. code below is working. However it puts red flags on the updated field .Is there a way to clear this.


var count = 1;

store.each(function(f) {
f.data.Seq = 5;
f.set("Seq", count);
count++;
});

mitchellsimoens
16 Feb 2012, 10:30 AM
You then would need to do a f.commit() after your store.each.