PDA

View Full Version : Dynamicaly adding fields to a store



spbroom
9 Jun 2009, 9:41 AM
Hi I had an idea to dynamicaly generate a datasore when needed by using a factory and passing in a table name as a parameter on the factory.

The idea was that the factory method would use the tablename to go off and and get an array of column names based on the table name and use them to dyamicaly populate the stores fields.

it's basic structure would be as follows:


Ext.namespace('DataStores');

getGoalStore=function(config)
{


var fields;



var connection = new Ext.data.Connection().request({
url : "fieldnames.php",

method : "POST",
params : {
action: "get_columnames",
table:config.tablename


},
success : function(o) {
fields=o.responseText;


}

});

return new Ext.data.JsonStore({

url : config
baseParams : config.baseParams,
fields : fields

]

});



}



Of course the problem is that the Connection is asynchronus so the Store is returned minus the fieldnames.

I could put a wait loop in there but dont want to do that.

I am wondering has anyone done anything similar or have any ideas about how to go about this.

I thought that maybe I could extend the store and include the field getting connection as part of the extended store, but am unsure if this would be possible or not.

I find myself using a lot of stores that differ only in the fields that they use

tryanDLS
9 Jun 2009, 10:16 AM
I think this is handled by MJ's Metagrid ux http://extjs.com/forum/showthread.php?p=275575#post275575

spbroom
10 Jun 2009, 2:03 AM
I think this is handled by MJ's Metagrid ux http://extjs.com/forum/showthread.php?p=275575#post275575


Hi thanks that seems to be pretty much what Im looking ofr alright. MJs example is of a grid including a store and column model all dynamically populated with the meta data.

All I want is the store, I have been trying to play around with the code to get that working but no succes so far. Im going to keep trying but if somebody has a quick example of this I would be very grateful!

Thanks