Grid sorts values from datasource instead of the value set by a renderer

Hi,
I have a Grid with numeric values in it which are rendered to String, e.g. the value ‘0’ is rendered as ‘Z’, the ‘1’ as ‘Y’ and ‘2’ as ‘X’. Now if this column is sorted, the sorting directions is wrong because the sorting alogorithm looks at the datasource and not at the rendered value. In the attachment is a little project which shows the mentioned issue. For a user this is very confusing. Is there a way, to get the sorting correct.

Thanks fpr your help and kind regards
Matthias
29429.zip (19.3 KB)

While I haven’t used it myself (yet), apparently one can
set
an
ItemSorter
on an
IndexContainer
, to define an order for the items. I guess you could implement such a sorter, based on the mapping numeric value ↔ string that you define anyway and simply set it on your container…

Thanks for your fast reply and your suggestion but as far as I know, the ItemSorter is set for the whole container and not only the one column with the renderer. That means, I would need something in the compare method, which I have to override, an indicator that the two compared objects are from the renderer column. Since this are integer or strings and in the rest of the tables are the same types, I cannot be sure that the compared values are from the rendered column.

Fair enough, I see your need…

Instead of simply

rendering

that certain column (as I see you are doing with your TestRenderer), you might actually try to

generate

it, as described
here
. In our current project we often present things in tables quite differently than their actual representation and we usually generate the involved columns, rather than simply rendering them differently. Granted, we are still using tables and not grid…