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?
Great thx Boris. Yep, I found this page quite useful.
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.
Hello gmoran1,
You could also take a look at the following link from our documentation, explaining the 'SortComparer' with examples:
http://help.infragistics.com/Help/NetAdvantage/WinForms/2013.1/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v13.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~SortComparer.html.
Please feel free to let me know if a question about our tool set comes up on your mind.
Hi,
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.
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!