PDA

View Full Version : add data to SimpleStore



hardyrah
25 Dec 2015, 4:23 AM
i am using Ext JS 4.1
i want to add data to the SimpleStore right after initializing


var test = new Ext.data.SimpleStore({
fields: ['id', 'value'],
data: [
['one', 'test1'],
['two', 'test2'],
['three', 'test3']
]
});
// test.data.push(['four', 'test4']); <- can anyone help me


also i cant find anything about SimpleStore in 4.1 docs

jdkhamba
25 Dec 2015, 6:17 AM
This looks like extjs 3.x syntax. ExtjS 4.x has changed significantly. Take a look at store definition:

http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.data.Store

What you are probably looking for is a store with a memory proxy:

http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.data.proxy.Memory

This loads in memory data to a store as opposed to a remote url end point.Also , you need to call store.add() method to append more data instead of manipulating the "data" property.

http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.data.Store-method-add

hardyrah
25 Dec 2015, 7:01 AM
This looks like extjs 3.x syntax. ExtjS 4.x has changed significantly. Take a look at store definition:

http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.data.Store

What you are probably looking for is a store with a memory proxy:

http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.data.proxy.Memory

This loads in memory data to a store as opposed to a remote url end point.Also , you need to call store.add() method to append more data instead of manipulating the "data" property.

http://docs.sencha.com/extjs/4.1.1/#!/api/Ext.data.Store-method-add

well it says its Ext Js 4.1
its shopware maybe they use a customized one D:

hardyrah
25 Dec 2015, 7:59 AM
nothing helped :-?
its shopware

just checked the ext-all.js there is a line
function(){ Ext.data.SimpleStore = Ext.data.ArrayStore}

jdkhamba
25 Dec 2015, 8:41 AM
In that case you will need an array reader like this:

var myStore = Ext.create('Ext.data.Store', {
fields: ['id', 'value'],
data: [
['one', 'test1'],
['two', 'test2'],
['three', 'test3']
],
proxy: {
type: 'memory',
reader: {
type: 'array'
}
}
});


myStore.add({id:'four',value:'test 4'});


console.log(myStore.getAt(3).getData());

hardyrah
27 Dec 2015, 10:45 PM
this did work for me:

test: function () {
var me = this;
var myStore = me.callParent();
myStore.on('load', function () {
myStore.add({
id: 'four',
value: 'test4'
});
});
return myStore;
}