View Full Version : ListView's attaching xindex field to Model's in

20 Aug 2012, 12:22 PM
I recently upgraded a project up to Touch and am noticing what seems the be errant behavior. When I have a ListView that pulls it's data from a store, each of the model records within the store get an xindex field appended into the model. This causes issues when I attempt to save my models. Is there a way to turn off adding this field into my models?

20 Aug 2012, 1:01 PM
Ok, I found the code that is causing me grief. In Ext.dataview.Dataview there is the following method that is called anytime you add a record to a store.

* Function which can be overridden to provide custom formatting for each Record that is used by this
* DataView's {@link #tpl template} to render each node.
* @param {Object/Object[]} data The raw data object that was used to create the Record.
* @param {Number} recordIndex the index number of the Record being prepared for rendering.
* @param {Ext.data.Model} record The Record being prepared for rendering.
* @return {Array/Object} The formatted data in a format expected by the internal {@link #tpl template}'s overwrite() method.
* (either an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'}))
prepareData: function(data, index, record) {
data.xindex = index + 1;
return data;

For my purposes, I will simply override the method so that it does not add that property to my model. Perhaps there is a better place to store xindex, that wouldn't stop us from saving our models?

22 Aug 2012, 5:48 AM
This has been changed in 2.1.0 that the xindex will be properly created and not do it in prepareData

22 Aug 2012, 5:50 AM
Ok, that's excellent news. As always think you guys for all the excellent work you guys do on this project.