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

Custom sorting

Hello there.

I need to create custom sorting.
I create custom comparer and set in SortColumnDescriptor.Comparer but in method Compare(x,y) I get values of record. We need to get records in Compare method. Please help.
int Capare(object x, object y)
{
Record r1 = (Record)x;
Record r2 = (Record)y;
}


3 Replies

AD Administrator Syncfusion Team November 15, 2007 10:41 AM UTC

The SortComparer works on what ever is in the column.

One way to do something like you described (getting access to the underlying data in the SortComparer) would be to add an unbound column that holds references to the underlying data objects. Attached is a little sample that sorts the column named Col1 by using a custom comparer on an unbound column holding the underlying data objects (DataRowViews in the sample case since the datasource is a DataTable).




WindowsApplication32.zip


VL Vladymyr November 15, 2007 11:09 AM UTC

Hello there.
It's works correctly. But add button in form it's not good. Is it possible to use standard sorting. For example if I click on the Column header the custom sorting appears.
And one more question.
I have in my grid more then 40 columns my custom sorting depends of sorting column. I dont want to creat more then 40 unbound columns for it. How can i do it?

I need for this behavior:
1. Click to any header column in grid
=> My custom sorting appears for this column.
Please help





AD Administrator Syncfusion Team November 15, 2007 11:33 AM UTC

One way to hook the sorting up to clicking the column headers is to catch the TableControlCellClick event and if the click is on a column header, do the sort using code similar to what was in the button handler.

I do not think you need more than one unbound column. You can create different custom comparers to do the different types of sorting for a particular column. Here is that sample modified so that when you click on a header, it sorts the grid using a custom comparer based on values in the column to the right of the clicked column. It does this with a single unbound column.



WindowsApplication32_1.zip

Loader.
Live Chat Icon For mobile
Up arrow icon