PDA

View Full Version : Model - Dynamically added fields are displayed in Grid but no values



skab
17 Oct 2014, 12:01 AM
Hello,

problem is as follows:

1. Defined a model

2. Created a store with this model and a proxy to load remote data. There is a listener for the load event which is calling a custom reconfigureGrid function which simply checks the fields in the stores model and creates a column model for the grid to call the grid original reconfigure function with the store and the new columnmodel.

3. Created a grid using this store with a default column at first.

Reason is to have generic functions for store and grid creation.

So, currently everything works as a charme.

Now i tried to go a little farther: I added code to the custom reconfigure function, which creates the column model.
This code checks the rawData of the store.proxy.reader object for fields which are not defined in the model and adds them to the model by


store.model.getFields().push(Ext.create('Ext.data.Field',{
name: tmpChild.localName,
type: "string",
convert: null
}));


Now, when the columnmodel for the grid is created, new colums will appear in the grid as expected and wanted.

My problem is, that no data is displayed wihin the grid in these newly added columns/fields. (all other columns are filled as expected)

I hope i made this somewhat clear.

Feel free to ask for further details.

kind regards
sven

watertrac_dev
17 Oct 2014, 5:07 AM
I've found that after modifying the fields of a given model it is necessary to reload the store. My process would go as follows:

1. Store is loaded
2a. Check for new properties on retrieved data
2b. If new properties are found, create the new fields on the model
2c. Reload the store (this is the step that populates the new fields of your model)
2d. Repeat at step 2a
3. Create column configurations to represent all fields
4. Reconfigure the grid with the new store and columns

slemmon
18 Oct 2014, 12:35 AM
If you have access to the data generated server-side you can pass the fields in a metaData block and the fields will be set for you.

See the Response MetaData section at the top of the JsonReader API doc for more information:
http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.data.reader.Json

skab
20 Oct 2014, 2:17 AM
Hey, thanks for your answer.
Sadly it looks like this does not work on my site.

I tried store.reload() and also store.loadRawData(store.proxy.reader.rawData);
Fields are displayed. Values of additional fields are not loaded.




I've found that after modifying the fields of a given model it is necessary to reload the store. My process would go as follows:

1. Store is loaded
2a. Check for new properties on retrieved data
2b. If new properties are found, create the new fields on the model
2c. Reload the store (this is the step that populates the new fields of your model)
2d. Repeat at step 2a
3. Create column configurations to represent all fields
4. Reconfigure the grid with the new store and columns

skab
20 Oct 2014, 2:19 AM
Hello, thanks for your answer.

I am using a XML-Store. Does this work with a XML store too?

How does the metaData structure shoud look like ?
I only could find documentation for JSON.




If you have access to the data generated server-side you can pass the fields in a metaData block and the fields will be set for you.

See the Response MetaData section at the top of the JsonReader API doc for more information:
http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.data.reader.Json

slemmon
23 Oct 2014, 9:47 PM
Ahh... sorry for the misdirection. The metaData option is only available for JSON via Ext.data.reader.Json (http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.data.reader.Json)