PDA

View Full Version : Fix for bug in SimpleStore when adding one record



tbenbrahim
31 May 2007, 5:28 PM
There is a bug in SimpleStore when adding a single record using loadData with append=true

for example:


supplierStore.loadData([[data.id,data.name]],true);

I was expecting my combo box tied to supplierStore to update, but it did not. turns out that the add event is fired from MixedCollection, where events["add"]=true, rather than from the store scope, where events["add"] points back to the view onAdd handler.

The changed code is in the loadRecords method of SimpleStore, although this is not the only way to fix this.


}else{
this.totalLength = Math.max(t, this.data.length+r.length);
var index = this.data.length; //added
this.data.addAll(r); //fires add , but in scope of MixedCollection, not SimpleStore
this.fireEvent("add", this, r, index); //added
}

Tony BenBrahim

jack.slocum
31 May 2007, 8:51 PM
Data loads don't fire an add event, only an add() does. A loadData (even if it's technically an addition) fires a 'load' event.

tbenbrahim
31 May 2007, 9:08 PM
it does fire a load event, however this does not update the contents of the combobox attached to the SimpleStore.
The first line it hits in the handler is if (!focused) return;, and that's the end of it.

Also add is not documented, only loadData... add looks like I have to pass records instead of raw array data, so it does not look as convenient.

Tony BenBrahim

Animal
1 Jun 2007, 1:30 AM
It still must inform any Views about some change, (eg a GridView, or a Combo's View, so that they can always reflect the state of the Model), so the "else" side in load records needs to fire a type of event that these listen for.

The Combo's View, just like GridView, listens for "datachanged" and "add" to change its view.

So as it stands, a Combo's View and a Grid's GridView won't be updated if records are appended.

jack.slocum
1 Jun 2007, 4:24 AM
It still must inform any Views about some change, (eg a GridView, or a Combo's View, so that they can always reflect the state of the Model), so the "else" side in load records needs to fire a type of event that these listen for.

The Combo's View, just like GridView, listens for "datachanged" and "add" to change its view.

So as it stands, a Combo's View and a Grid's GridView won't be updated if records are appended.

Ah, I see what you mean now. I have rearranged things a bit and submitted the change to svn.