Unplanned
Last Updated: 29 Apr 2021 12:48 by Peter
Cameron
Created on: 19 Oct 2017 15:23
Category: Grid
Type: Feature Request
3
Radgrid - Sort null values last
I think it would be a great addition to the grid control if there was an attribute that you could apply to the columns called "SortNullsLast" or something along those lines. This attribute would modify the grid's sorting functionality and only apply the ascending or descending sort to non-null values.

Currently when you sort ascending, null values are sorted to the top of the grid. This new attribute would allow the non-null values to show up at the top in ascending order.

An example of why this would be useful is having a grid that tracks an optional requested completion date of a task. You would want to be able to sort the grid so that the earliest date shows first in the grid. Right now, any records that don't have this optional date would show first, which doesn't make sense.
1 comment
Peter
Posted on: 29 Apr 2021 12:48

This would be fantastic !

In the normal old winform datagridview it was simply possible by "SortCompare".. i would like to buy the radgridview but as far as this is not availabel, i cant.. my customers need it.

 

anyway old solution was :

-----------------------

    Private Sub DG_RM_SortCompare(sender As Object, e As DataGridViewSortCompareEventArgs) Handles DG_RM.SortCompare


        '''' <summary>Gets or sets a value indicating the order in which the compared cells will be sorted.</summary>
        '''' <returns>Less than zero if the first cell will be sorted before the second cell; zero if the first cell and second cell have equivalent values; greater than zero if the second cell will be sorted before the first cell.</returns>

        If e.Column.Index > 2 Then
            Try
                If e.CellValue1 Is Nothing OrElse e.CellValue1.Equals(DBNull.Value) Then
                    If e.CellValue2 Is Nothing OrElse e.CellValue2.Equals(DBNull.Value) Then
                        e.SortResult = 0
                    Else
                        e.SortResult = 1
                    End If
                Else
                    If e.CellValue2 Is Nothing OrElse e.CellValue2.Equals(DBNull.Value) Then
                        e.SortResult = -1
                    Else
                        e.SortResult = DirectCast(e.CellValue1, IComparable).CompareTo(DirectCast(e.CellValue2, IComparable))
                    End If
                End If
                e.Handled = True

            Catch ex As Exception
                MsgBox(Err.Description)
                Close()
            End Try
        End If

    End Sub