We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Adding a custom sorter to a column on a dbdg

Hi, I want to customize the sort behavior of an ID column as follows: CMJGB10Y CMJGB2Y I tried creating a custom object with the IComparable interface, but the dbdg does not appear to call this compare to. I read the GridControlSort project, but that method doesnt seem to map onto dbdg easily. How can I make the dbdg sort this column with my custom sorting behaviour? There should be an easy way such as overriding IComparable.

3 Replies

AD Administrator Syncfusion Team August 23, 2004 09:24 AM

Attached is a sample that sorts a column based on string.length by having a custom object implement IComparable. If your custom object is not editable in the grid, then this would be all you would need I think. But if your custom object needed to be editable within the grid''s UI, then you would need more work, maybe deriving a cell control that understood your object and how to edit it. GDBGDataView_6877.zip


NA Navid May 5, 2008 01:30 AM

Could you please make a sample for ASP.NET?
Thank you!

Navid

>Attached is a sample that sorts a column based on string.length by having a custom object implement IComparable. If your custom object is not editable in the grid, then this would be all you would need I think. But if your custom object needed to be editable within the grid's UI, then you would need more work, maybe deriving a cell control that understood your object and how to edit it.
>
>GDBGDataView_6877.zip
>
>



JA Janagan Syncfusion Team May 8, 2008 10:32 AM

Hi Navid,

Thank you for evaluating Syncfusion Products.

You can sort the columns using Icomparable interface based on the length of the string in the cell of the grid by the following code:




public class MyObject : IComparable
{
public MyObject(string s)
{
this.s = s;
}
public override string ToString()
{
return s;
}

string s;
public string Val
{
get { return s; }
set { s = value; }
}

public int CompareTo(object obj)
{

return this.ToString().Length - obj.ToString().Length;
}



Please refer the sample in the link below which illustrates the above:

http://websamples.syncfusion.com/samples/Grid.Web/6.2.0.40/Grid_ASP_sortinggrid/main.htm



Please try running this and let me know if this helps.

Thanks,
Janagan.








Loader.
Live Chat Icon For mobile
Up arrow icon