Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
300
Custom comparer on multiple columns
posted

I have field Songname, which can be A, B or C, and field TrackNumber that can be -5 to 5. Now I want to sort as follows:

  • The primary sort depends on both fields. It sorts by ascending order of name if the track number is positive, and descending order of name if the track number is negative. So (A, 2) < (B, 2), but  (A, -2) > (B, -2). 
  • If the rows are equivalent by the first sorting criterion, then they are compared based on the value of the track number, so -3 < -1 < 2.

Now I see its possible to apply a custom comparer on a single field, or apply simple sorting on multiple columns, but what I need to do is create a comparer that receives the entire record object (or at least these two fields), and then sorts based on the combined value of the two fields. How do I do this?

Thanks 

  • 27093
    posted

    Hello,

    I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.

    If the above suggestion helped you solve your issue please verify the thread as answered so other users may take better advantage of it.

  • 27093
    Verified Answer
    posted

    Hello Neil, 

    I have been looking into your requirement and I can suggest you create a hidden UnboundField, that would be bound to the whole record object and you can use your custom Comparer on it. I have created small sample project for you so you can see what I mean (Grid_wholeRecordSorting.zip). Please note that the comparer I created does not specifically follow your description, but rather only shows how multiple properties can be used. 

    Please let me know if you require any further clarification on the matter.

    Grid_wholeRecordSorting.zip