the datasource for the ultragrid is SQL data rows. one of the columns "SortOrder" is int type in SQL.
when I click on the header of this column, it does the sorting, but it sorts the column treating the numbers as strings. The result is like 1 10 11 12 .....2 20 21...
How do I config the column setting to enable numeric sort?
Thank you,
If the data is being sorted as strings, then it must be string data in the grid. Your data source must somehow be converting the ints into strings for some reason.
I seem to have this problem too. However, the underlying data is Integer, but I have a valuelist that converts the Integer value to String. When I sort, it still sorts the data by display value (string) rather than by underlying data value. Is there any way when I sort, it sorts by underlying value and not by display text?
Hi,
The grid sorts by what the user sees. But you can change this using a SortComparer on the column that examines the Value of each cell and ignores the ValueList.
Or, an alternative would be to set the SortStyle on your ValueList to ValueListSortStyle.AscendingByValue or ValueListSortStyle.DescendingByValue. This will sort the items in the list and also let the grid know that the column should be sorted by value and not by the display text.
Hi Mike, I'm trying to do the same thing, but am confused about distinguishing between/specifying different values for display vs underlying value for a column. I'm not using drop-downs, so not sure if "ValuerList" applies for me. My data source is a ADO.Net DataSet; I want to show a textual format for a numeric value, but sort on the raw numeric value when the col header is clicked. I believe I can use "SortComparer", but seems like all I could do is grab the display text and somehow try to get back to the raw numeric form for the comparison and I'd rather just store the discrete numeric/display values somewhere and directly reference in "SortComparer". Thx!
The SortComparer is an IComparer interface. This interface has only one method: Compare. The Compare method will pass you two values, x and y. In the case of a SortComparer, these two values will each be an UltraGridCell.
So you can examine the cell and get any information you want from the that cell. In your case, you will probably want the cell.Value of each cell. And then you can return a value based on the comparison between those two values.
Thx Mike, that's what I ended up with it works great. I figured I needed a place to store the formatted (string) and raw (numeric) values and couldn't figure out how to do that with just the 1 "Value" cell property or bound dataset cell value, so I actually added a numeric sorting col (and hid it) and pointed to that col in the "Compare()" method I'd assigned to the "display" col version.
I had 1st gone down the path of using a 2-element string array ([0]=display value and [1]=raw numeric value) for the bound dataset col value that had display and raw properties so I could display the display value and sort on the raw numeric value. I then tried using "BeforeSortChanged" event where tried to replace "SortedColumns" with the hidden numeric cols to sort on them that way. I then went the route of using "ExternalSortSingle", where I left the raw numeric value in the underlying dataset, sorted that, then handled display via code. Then I realized I could just refer to the hidden numeric cols for sorting as the subject of my compares in right in the "Compare()" method, so I went with that.