GridDataSortColumn CustomComparer doesn''t work
Hello,
I try to make sort numeric on datacolumn whith dataType = typeof(string); because some rows are empty, adn the others are fill witrh numerics values.
So, i try to implement a CustomComparer on a column. But the compare function was never called.
void Table_SortColumnsChanging(object sender,GridDataSortColumnsChangingEventArgs args)
{
foreach (var item in args.AddedItems)
{
if (item.ColumnName.Equals("LABEL_TAPP_COLUMN_NAME"))
{
item.CustomComparer = new NumericSort();
item.SortDirection = ListSortDirection.Ascending;
}
}
}
I try to make sort numeric on datacolumn whith dataType = typeof(string); because some rows are empty, adn the others are fill witrh numerics values.
So, i try to implement a CustomComparer on a column. But the compare function was never called.
void Table_SortColumnsChanging(object sender,GridDataSortColumnsChangingEventArgs args)
{
foreach (var item in args.AddedItems)
{
if (item.ColumnName.Equals("LABEL_TAPP_COLUMN_NAME"))
{
item.CustomComparer = new NumericSort();
item.SortDirection = ListSortDirection.Ascending;
}
}
}
SIGN IN To post a reply.
2 Replies
BE
berthet
April 13, 2011 08:52 AM UTC
Excuse me the message was post before it was finish.
public class NumericSort : System.Collections.Generic.Comparer<object>
{
public NumericSort():base()
{
System.Diagnostics.Trace.WriteLine("NumericComparer: creation");
}
public override int Compare(object x, object y)
{
System.Diagnostics.Trace.WriteLine("NumericComparer: Compare");
string sX = x.ToString();
string sY = y.ToString();
if ((sX != string.Empty) && (sY != string.Empty))
{
// System.Diagnostics.Trace.WriteLine(string.Format("NumericComparer: Compare {0} , {1}", sY, sY));
int ix = int.Parse(sX);
int iy = int.Parse(sY);
// return ix - iy;
// * If they are both null, return 0
//* If x is null but not y, return -1 (x < y)
// * If y is null but not x, return 1 (x > y).
if (ix < iy)
{
return -1;
}
else if (ix < iy)
{
return 1;
}
else
{
return 0;
}
}
else
{
if (sX == string.Empty && sY == string.Empty)
{
return 0;
}
else if (sX == string.Empty)
{
// int iy = int.Parse(sY);
// return - iy;
return -1;
}
else
{
// int ix = int.Parse(sX);
// return ix;
return 1;
}
}
}
}
Constructor was call, but compare function no.
Have you some example on CustomComparer ?
public class NumericSort : System.Collections.Generic.Comparer<object>
{
public NumericSort():base()
{
System.Diagnostics.Trace.WriteLine("NumericComparer: creation");
}
public override int Compare(object x, object y)
{
System.Diagnostics.Trace.WriteLine("NumericComparer: Compare");
string sX = x.ToString();
string sY = y.ToString();
if ((sX != string.Empty) && (sY != string.Empty))
{
// System.Diagnostics.Trace.WriteLine(string.Format("NumericComparer: Compare {0} , {1}", sY, sY));
int ix = int.Parse(sX);
int iy = int.Parse(sY);
// return ix - iy;
// * If they are both null, return 0
//* If x is null but not y, return -1 (x < y)
// * If y is null but not x, return 1 (x > y).
if (ix < iy)
{
return -1;
}
else if (ix < iy)
{
return 1;
}
else
{
return 0;
}
}
else
{
if (sX == string.Empty && sY == string.Empty)
{
return 0;
}
else if (sX == string.Empty)
{
// int iy = int.Parse(sY);
// return - iy;
return -1;
}
else
{
// int ix = int.Parse(sX);
// return ix;
return 1;
}
}
}
}
Constructor was call, but compare function no.
Have you some example on CustomComparer ?
RA
Rajasekar
Syncfusion Team
April 19, 2011 08:35 AM UTC
Hi Berthet,
Thanks for your update.
We have prepared the sample based on your requirement, please find the sample in the following location,
Sample: < http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=CustomSorting_Sample465204710.zip >
Please let us know if you have any queries.
Thanks,
Rajasekar
Thanks for your update.
We have prepared the sample based on your requirement, please find the sample in the following location,
Sample: < http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=CustomSorting_Sample465204710.zip >
Please let us know if you have any queries.
Thanks,
Rajasekar
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
BE berthet
- Apr 13, 2011 08:49 AM UTC
- Apr 19, 2011 08:35 AM UTC