GridView Sort Behavior Issue

6 posts, 0 answers
  1. Dave
    Dave avatar
    29 posts
    Member since:
    Aug 2010

    Posted 12 Aug 2011 Link to this post

    Hi,

    Our application is very customizable so we allow users to set a sort by member on all grid views ahead of time. So, in essence, the data in the gridview is already sorted on a particular column when it is bound (by way of an ORDER BY clause on the SQL statement), only the gridview column isn't aware of this. I tried programmatically adding a SortDescriptor to the column that the data is sorted on, but it doesn't solve the issue of having to click extra times to make the column aware of this pre-sort.

    Is there a way to add a SortDescriptor programmatically in such a way that the column header button behaves in a similar way to if the user had clicked it (ie, show as a different style, have ascending toggled on)?
  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 14 Aug 2011 Link to this post

    Hi Dave,

     
    You should use ColumnSortDescriptor instead. 


    Kind regards,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
  4. Dave
    Dave avatar
    29 posts
    Member since:
    Aug 2010

    Posted 15 Aug 2011 Link to this post

    I've tried this a few times and while I get the data in the grid view to sort, the column header does not toggle it's sort. Here is my code.
    ColumnSortDescriptor descriptor = new ColumnSortDescriptor();
    descriptor.Column = grid.Columns[1];
    descriptor.SortDirection = System.ComponentModel.ListSortDirection.Ascending;
    grid.SortDescriptors.Add(descriptor);

    I have my grid pre-sorted when it is created this way. However, in this instance, if the user wants to sort by this column, but instead of Ascending, they want Descending, they have to click the column twice. The first click will just sort by Ascending again. Is there any way to make the column sort button aware that it's sorted, so the next click will sort Descending?
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 15 Aug 2011 Link to this post

    Hello Dave,

     

    I will try to explain the default behavior when you sort through clicking on column header. When you click on the column header the sorting state is changed from None to Ascending, the next click changes it to Descending and the third one brings the None state back. You may turn the default sorting off state through subscribing to the Sorting event of RadGridView as shown below:


    private void clubsGrid_Sorting(object sender, GridViewSortingEventArgs e)
    {
    if (e.NewSortingState == SortingState.None)
    {
     e.NewSortingState = SortingState.Ascending;
    }
    }


    Then when you click on the header the sorting will go only from Ascending to Descending. 


    Regards,
    Vanya Pavlova
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  6. Vahan
    Vahan avatar
    4 posts
    Member since:
    Sep 2014

    Posted 26 Mar 2015 in reply to Vanya Pavlova Link to this post

    Hi Dave, 

    I know that is very late to naswer to this question but I just had the same problem as you have described below. I have a grid that came from DB already sorted and grid doesn't know about it. Creating a new sorting descriptor and adding to the grid doasn;t help (which I thing very strange, indeed if grid has sorting member name it and sorting direction is not None, it should display the arrow in it).
    Indeed to display an arrow on the particular column you should set the SortingState property of that column (either Ascending or Descending).
    Now I have a question to Telerik team:
     Don't you think that it's a bug when I'm setting proper sorting descriptor to the grid and it doesn't set corresponding column properties that it (Column) could have the same appearance as it having on clicking on it?
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Mar 2015 Link to this post

    Hello,

    When the user sorts on a column, then a ColumnSortDescriptor is added. Also, in case a SortDescriptor is applied before having RadGridView populated, this may be a reason for the SortingState to be not reflected although the underlying data is sorted. 
    Would it be possible for you to illustrate the specific case in a demo project with your exact setup and send it to us via a new support thread? You can also take a look at this blog post for a reference on how to isolate an issue.  

    Regards,
    Dimitrina
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
DevCraft banner