PDA

View Full Version : Grid - How to get rendered data in view



talha06
23 Oct 2012, 4:47 AM
Hello everyone,

I'm trying to get all rendered data in the grid. Before Ext JS 4.x, we could do this with using selection model.
Now I wasn't able to find a suitable method for this. I'm trying this way instead of getting data from store because of
I've some rendered lookup values to offer user-friendly description.

I'll be happy if someone can help me.
Thanks in advance.

James Goddard
23 Oct 2012, 4:52 AM
If you need the converted data you should do the conversation in the model with 'convert' instead of in the grid with 'render'.

Your data is in the model, you shouldn't be pulling it from the screen.

talha06
23 Oct 2012, 5:13 AM
If you need the converted data you should do the conversation in the model with 'convert' instead of in the grid with 'render'.

Your data is in the model, you shouldn't be pulling it from the screen.
Let me give you an example of my situation:
I've a grid for users. And I store user's sex as integers like 1,2.
If I use converter, I'll loss these key values which I need to use for further actions on grid.
So I'll use another field to store these numeric key values. This means we keep same value twice.
But the rendered data isn't used most times. For example I need these rendered values for a generic export mechanism that I'm implementing nowadays.

Please correct me if there's something wrong.
Thanks.

James Goddard
23 Oct 2012, 5:34 AM
Let me give you an example of my situation:
If I use converter, I'll loss these key values which I need to use for further actions on grid.
...
Please correct me if there's something wrong.


Only if you covert the key values in place. Instead convert them into a new field:



fields: {
{ name: 'gender', type: 'int' },
{ name: 'genderText', type: 'string', convert: function (value, record) {
return 1 == record.get ('gender') ? 'male' : 'female';
} }
}


Now you have both the key and the text in the model. Your grid, and wherever else, can use genderText but you still have the number.

talha06
23 Oct 2012, 6:55 AM
OK got it.. I've been using grid column renderer because of most samples by Sencha (http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/).
I thought maybe there is a way to get rendered data without making any changes to model.

Thanks my mate.

James Goddard
23 Oct 2012, 7:04 AM
No problem. Using a column renderer makes perfect sense if that is the only place you need the converted data. In your case since you need it elsewhere better to do it in the model.