View Full Version : How to handle key-value fields in a grid?

29 Jul 2012, 1:21 AM
I have several models with related key-value fields. For example - country code and country name to represent a "country.
I want to display a "country" column in a grid. Obviously the display field should be the country name, but I also want the editing plugin capabilities.

This is what I've done:

Used "country_code" as my dataIndex
Defined a renderer function that displays the record's "country_name" field
Used a combo-box editor (displayField = country_code, valueField = country_name)
This way the grid displays the country name, but the editor also works. The editor actually changes the "country_code" field, so I had to add an update event to the store that will update the country name when the country code changes...

This way works, but it causes other problems, for example, when a user is sorting by this column it actually sorts the country code (where he clearly needs to sort by country name)

Is there a more elegant solution than what I've done? It seems like quite a mess... :-|

Thanks in advance for you help,

29 Jul 2012, 2:27 AM
Have a look at the thread "Sorting one column based on another column (http://www.sencha.com/forum/showthread.php?200917-Sorting-one-column-based-on-another-column)". Hope this will help you.

29 Jul 2012, 2:56 AM
Thanks, it does help with the sorting problem.
If someone has a different, cleaner, solution to this whole situation please let me know.

Thanks again for your help! :)