-
27 Jan 2012 10:51 AM #1
PR4 Store insert method ignoring index
PR4 Store insert method ignoring index
I'm running into a strange problem with PR4 that didn't exist in PR3. The store.insert method is ignoring the index and adding the record to the bottom of the list. The store is loaded using the ajax proxy.
My guess is that the insert is being performed before the store is loaded, but that should not be the case when called after the load event has fired.
Code:store.on({'load': function(store, records, successflag, oper) { // Remove any previously added optional labels if (store.getAt(0).data.optional === true) { store.removeAt(0); } // If a label is passed, add it if (label) { store.insert(0, [{name: label, optional: true}]); commList.down('list').select(0); } }, scope: this });
-
27 Jan 2012 11:13 AM #2
Moved to bug forums. Thanks.
Sencha Inc.
Robert Dougan - @rdougan
Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.
-
27 Jan 2012 3:09 PM #3Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
With the following test case on our latest code branch, the result is correctly
I'm sending back the following test json:Code:Ext.define('MyModel', { extend: 'Ext.data.Model', config: { fields: [ 'field1' ], proxy: { type: 'ajax', url: 'read.json', reader: { type: 'json', rootProperty: 'results' } } } }); Ext.setup({ onReady: function() { var store = Ext.create('Ext.data.Store', { model: 'MyModel' }); var dataview = Ext.create('Ext.DataView', { store: store, fullscreen: true, itemTpl: 'Field1: {field1}' }); store.on({ load: function(store, records, successflag, oper) { store.insert(0, [{field1: 'Should be first'}]); }, scope: this }); store.load(); } });
What I suspect is that you have a sorter active on your Store. In the new data package, the collection is always up to date in terms of sorting. This means that if you insert a record at index 0, but the sorting would cause the item to be somewhere else in the list, it would ignore your index 0 and instead move it to the right location based on the sorter.Code:{ "success": true, "results": [ { "field1": "blaat1" }, { "field1": "blaat2" }, { "field1": "blaat3" } ] }
Could you please confirm if this could be the case? If so, I'll reopen this ticket. In the meantime I'm closing this ticket as I cannot reproduce in the latest code base.
-
27 Jan 2012 5:34 PM #4
I apologize. I did have a sorter that caused the problem.
However, the sorter was sorting on a field that did not exist in the returned json or the model used by the store. For some reason, this still affected the sort order.
-
27 Jan 2012 6:20 PM #5Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
Ok, that sounds like something that could be improved. I guess when the sorter executes and the value is always undefined, it still pushes it to the end of the list, which actually doesn't sound completely unreasonable but might not be expected behavior.
In any case, it sounds like that sorter shouldn't have been there if the field it was sorting on didn't actually exist
Glad it fixed your issue.
Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-1648
in
2.0.


Reply With Quote
