This is a migrated thread and some comments may be shown as answers.

Problem with AllowNaturalSort

4 Answers 80 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 15 Sep 2009, 12:44 PM
I am using the Q2 2009 version of the grid control.  The AllowNaturalSort property is set to True, but when I click on the grid column header it only toggles between sorting Asc and Desc.  The documentation says that it should go from Asc -> Desc - > Unsorted, but this does not happen in my grid.  Is there a bug with the AllowNaturalSort property?  I want to be able to toggle the sorting simply by clicking the column header (no extra button to remove sorting).

Thanks,
Sean

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Sep 2009, 01:26 PM
Hi Sean,

There is a bug in our documentation. You can remove the sorting by using the context menu Clear sorting option. If you need further assistance, please write back.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sean
Top achievements
Rank 1
answered on 15 Sep 2009, 01:33 PM
Thanks for the quick reply.  However, I have disabled the grid context menu, and I think it would be unclear for users to know that they can sort by clicking on the column header, but they have to right click and choose "Clear" to remove sorting.  What I would really like to be able to do is when clicking the column header rotate through the different sort options (Asc, Desc, No Sort).  I tried handling the SortChanging event of the grid, but did not have any luck.  Could you please advise?

Thanks,
Sean
0
Sean
Top achievements
Rank 1
answered on 15 Sep 2009, 09:04 PM
Okay, this is the workaround that I came up with (for anyone who is interested).

I created a member variable  named _previousGridColumnSortDirection which is used to indicate the sort direction from the last time the column was sorted.  If this is set to descending and the current sorting is Ascending then I clear out the sorting.  This seems to work so far with no issues.

Private Sub rgvLines_SortChanged(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCollectionChangedEventArgs) Handles rgvLines.SortChanged  
        Dim sortField As GridSortField  
 
        'Only proceed if we are changing an existing sorting (not starting a new one)  
        If e.Action = Data.NotifyCollectionChangedAction.ItemChanged Then 
 
            'Make sure we have an item  
            If e.NewItems IsNot Nothing AndAlso _  
                e.NewItems.Count > 0 Then 
 
                sortField = CType(e.NewItems(0), GridSortField)  
 
                'If the current SortOrder is Ascending, and the previous SortOrder was Descending, then  
                'clear the sorting.  
                If sortField.SortOrder = RadSortOrder.Ascending AndAlso _  
                    _previousGridColumnSortDirection = RadSortOrder.Descending Then 
 
                    sortField.SortOrder = RadSortOrder.None  
 
                End If 
 
                'Save the SortOrder for the next iteration  
                _previousGridColumnSortDirection = sortField.SortOrder  
 
            End If 
 
        End If 
 
    End Sub 
0
Jack
Telerik team
answered on 16 Sep 2009, 08:28 AM
Hi Sean, I tested your workaround. Nice job. Thank you for sharing it with the community. We will consider adding this option in one of our upcoming releases.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Sean
Top achievements
Rank 1
Answers by
Jack
Telerik team
Sean
Top achievements
Rank 1
Share this question
or