PDA

View Full Version : How to set model for Ext.data.Store on fly



mkysoft
20 Jun 2012, 3:29 AM
Hello,

How can I change model config for Store on fly? Thanks.

scottmartin
20 Jun 2012, 2:56 PM
Can you explain what you have in mind?

Scott.

mkysoft
20 Jun 2012, 10:37 PM
I want to use same store with grid and combobox with different model.

scottmartin
21 Jun 2012, 10:11 AM
You can use setModel on your proxy/reader.

Scott.

Ex_Soft
21 Jun 2012, 11:16 PM
You can use setModel on your proxy/reader.



Ext.onReady(function() {
if(window.console && console.clear)
console.clear();

var
TestModel1 = Ext.define("TestModel1", {
extend: "Ext.data.Model",
idProperty: "id",
fields: [
{ name: "id", type: "int" },
{ name: "name", type: "string" }
]
}),
TestModel2 = Ext.define("TestModel2", {
extend: "Ext.data.Model",
idProperty: "id",
fields: [
{ name: "issmth", type: "boolean" },
{ name: "name", type: "string" },
{ name: "id", type: "int" }
]
}),
store = new Ext.data.Store({
model: "TestModel1"
}),
data1=[
[ 1, "Record# 1" ],
[ 2, "Record# 2" ],
[ 3, "Record# 3" ]
],
data2=[
[ false, "Record# 1", 1 ],
[ false, "Record# 2", 2 ],
[ true, "Record# 3", 3 ]
],
tmpRec;

store.loadData(data1);

if(window.console && console.log)
console.log("All record(s) (TestModel1)");

store.each(function(r)
{
if(window.console && console.log)
console.log("id=%i name=\"%s\"", r.get("id"), r.get("name"));
});

store.getProxy().setModel(TestModel2 /* "TestModel2" */, true);
store.loadData(data2);

if(window.console && console.log)
console.log("All record(s) (TestModel2)");

store.each(function(r)
{
if(window.console && console.log)
console.log("id=%i name=\"%s\" issmth=%s", r.get("id"), r.get("name"), r.get("issmth"));
});
});

4.0.7/4.1/4.1.1-rc2 doesn't work.