View Full Version : Sorting Scientific values and Decimals in a Grid column

31 May 2010, 5:30 AM

I have grid with a column that has decimal values like (1.6,2.3,0.2) as well as exponential values like (3e-70,4e-80) etc etc. When I try to sort the column then it just sorts the data in lexicographical manner i.e. 2 is put before 3e-70 while sorting in an ascending manner. I tried using a numberRenderer as:

NumberFormat format = NumberFormat.getScientificFormat();
final NumberCellRenderer<Grid<BeanModel>> cellRenderer = new NumberCellRenderer<Grid<BeanModel>>(format);

GridCellRenderer<BeanModel> gridNumber = new GridCellRenderer<BeanModel>() {
public String render(BeanModel model, String property, ColumnData config, int rowIndex,
int colIndex, ListStore<BeanModel> store, Grid<BeanModel> grid) {
return cellRenderer.render(null, property, model.get(property));

and then using this renderer in my column config as:

column = new ColumnConfig("minEVal","Min E-Val",75);

But it seems not to be working. Any ideas?

- Parit

31 May 2010, 5:32 AM
what type are your values? Do you have them as a string?

31 May 2010, 6:24 AM
yes of course.. got it fixed :) thankx..

- Parit

31 May 2010, 6:25 AM
So please post your solution so others can use it too

31 May 2010, 6:31 AM
As it turned out.. the fields of the model class that were rendered by the grid were strings instead of being double thats why when a sort is called on a column then the items in it were sorted lexicographical and not as numbers. So, I just changed the relevant fields from String to double. problem solved :)