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

GridView Sort Behavior Issue

5 Answers 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 12 Aug 2011, 09:56 PM
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)?

5 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 14 Aug 2011, 03:01 PM
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 >>

0
Dave
Top achievements
Rank 1
answered on 15 Aug 2011, 06:33 PM
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?
0
Vanya Pavlova
Telerik team
answered on 15 Aug 2011, 07:34 PM
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 >>

0
Vahan
Top achievements
Rank 1
answered on 26 Mar 2015, 11:18 AM
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?
0
Dimitrina
Telerik team
answered on 30 Mar 2015, 01:59 PM
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.

 
Tags
GridView
Asked by
Dave
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Dave
Top achievements
Rank 1
Vahan
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or