Hi,
I want to use Excel-style soring for my text column so that it sorts values as 1,2,..10,11 instead of 1,10..2,20.. as would be the default for test sorting.
Thanks in advance
Regards
Habib
You have two options.
The first and easiest is to use a numeric datatype, such as int or double, for the data in the underlying grid column. By default, the grid will sort using the IComparable implementation of the data type, so numbers get sorted as numbers and strings as strings.
The other way, more powerful but requiring more code to accomplish, is to implement your own SortComparer. The API documentation for the SortComparer property of the UltraGridColumn class (from the online help documentation for NetAdvantage for .NET 2008 Volume 3) provides more detail and a simple example implementation.
Hi Vince,
Is there a way to do this for a UltraWebGrid? I am in urgent need of a solution and I cannot seem to find one.
Thakns,
Dan
Thanks for the answer. I implemented a SortComparer , as below.
public class SortComparer : IComparer
{
}
// Passed in objects are cells. So you have to typecast them to UltraGridCell objects first.
UltraGridCell yCell = (UltraGridCell)y;
// convert the compared values to string
// if both values are numeric, compare as numeric; if one them is numeric bump it up; else compare as string
decimal Num2;
decimal.TryParse(text2, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out Num2);
else
double retNum;