:: Forum >>

Display a grid column as an image but sort based on a number?

Is it possible to have a grid column display an image, but sort based on numeric data that's somehow hidden in the cell?

Suppose I have a column named 'count' which stores, well, the count of something. I don't want to display the actual count -- I want to display an exclamation point image if the count is greater than some threshold. If the count is less than this threshold, nothing should be displayed in the cell. However, when I sort based on this column, I *do* want to use the real count to order the rows.

I've tried stuffing the text inside a hidden <span> in the cell and using AW.Formats.HTML, but that doesn't work because then the sorting is string-based and not numeric. I've tried using AW.Formats.Number, but then I don't get any sorting at all (I assume because it's trying to interpret the cell content as a number when it's actually an <img> tag).

I've been able to stick an image into a cell based on the count (in which case the sort is essentially based on whether the image exists or not). I've been able to sort based on the count itself (if I store the count in the cell -- in which case I don't have the image). I haven't yet figured out how to tie the two of these together.

I think perhaps a custom AW.Format class that combined AW.Formats.HTML & AW.Formats.Number might do the trick, but if there's an easier way that didn't require patching the code I'd rather do that.

Any ideas?
Trevor
Friday, May 19, 2006
I have just done it this way:
I have a status for each row: red, orange, green.
Each status is represented by a number: 1,2,3
In the data for the table, the numbers are inserted.
But then i change the template of the column which should display the status to AW.Templates.Image like this:
obj.setCellTemplate(new AW.Templates.Image,2);

Then I do a loop over all rows and set the image based on the data of the cell:
obj.setCellImage("red|orange|green",2,i);
(depending on the data for this cell)

After that the according images are showed, but they are sorted after the values of the cells. This works really nice, but it was only easy to do for me, because the javascript code is generated from PHP and there i know the status of each row. So I dynamicaly generate the javascript code which sets the images. :-)
Shyru
Monday, May 22, 2006
That should not be a problem if you use AW.Templates.Image and define your images in CSS as described here -

http://www.activewidgets.com/grid.howto.cells/images.html

Then you can still set any sort order using cell/value property obj.setCellValue(...).
Alex (ActiveWidgets)
Wednesday, May 24, 2006

This topic is archived.


Back to support forum

Forum search