Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-1648
in
a recent build.
-
Sencha User
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
});
-
Sencha User
Moved to bug forums. Thanks.
-
Sencha User
With the following test case on our latest code branch, the result is correctly
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();
}
});
I'm sending back the following test json:
Code:
{
"success": true,
"results": [
{
"field1": "blaat1"
},
{
"field1": "blaat2"
},
{
"field1": "blaat3"
}
]
}
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.
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.
-
Sencha User
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.
-