PDA

View Full Version : Translate values in grid



devtig
6 Aug 2010, 6:19 AM
I have an editable grid with a store containing data from a table in my database. This is what the table contains and what the grid shows now.


pk code fk
1 aaa 1
2 bbb 1
3 ccc 2
4 ddd 2


But I want it to show something different, because fk is a reference to a different table fk=1 means xxx and fk=2 means yyy. So what I want the grid to show is this:


pk code fk
1 aaa xxx
2 bbb xxx
3 ccc yyy
4 ddd yyy

However in the background the store must still contain 1 and 2 instead of xxx and yyy so I can change a record and keep the numerics (which the database needs).

For example, I might want to change record with pk=3 from yyy to zzz (zzz means fk=3). I already configured the fk column with a combobox editor. So, when I click the cell that I want to change I get a combobox showing the values: xxx, yyy and zzz. But after I choose zzz, I get to see 3 again. Which is technically correct, because that's what the store contains after I choose zzz from the combobox. And 3 is also the value that I want to submit to the database. BUT I want to séé zzz in the grid.

Any idea's? I've been think of some convert or translation function, but the foreign key table may contain 10.000 records.

Condor
6 Aug 2010, 6:22 AM
Use a ComboColumn (see the Feature Request section).

devtig
9 Aug 2010, 3:44 AM
The ComboColum (http://www.sencha.com/forum/showthread.php?67488-3.x-Ext.grid.ComboColumn-amp-Ext.util.Format.comboRenderer&highlight=combocolumn) is exactly what I need. Depending on the timing in my application I did not always see the value zzz in the grid, because the store of the combobox wasn't loaded yet. When i'd refresh the grid a second later then I do see the values.

I've thought of using the technique used in this override (ComboBox's setValue call with a remotely loaded Store (http://www.extjs.com/forum/showthread.php?t=75751)) for the ComboColumn so that Ext.util.Format.comboRenderer would work with remotely loaded stores that might not be loaded yet. But, I'm seeing to much stuff I don't understand yet in that override.