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

Programmatically Sorting doesn't update sorting indicator

9 Answers 136 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rupendra
Top achievements
Rank 1
Rupendra asked on 26 May 2011, 06:25 PM
The application I am working on requires a user to click on a navigation bar item after which I apply a sorting on the grid programmatically to display the loaded data. The sorting is applied correctly in every case I speak of. The issue is regarding the display of the sort indicator and is in context of programmatic sorting and not user initiated sort. The issue is that the sort indicator is visible only after grouping is applied. Moreover, I found that the indicator wasn't applied consistantly for columns with column indexes greater than 3.

I am using version 2011.1.516.1040 of the gridview.

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 27 May 2011, 06:14 AM
Hello,

 Do you have some code showing the issue? How exactly you've added sorting - are you using ColumnSortDescriptor? 

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rupendra
Top achievements
Rank 1
answered on 27 May 2011, 03:03 PM
The code that is being used to add the sort descriptor is given below.

            .
            .
            .
            ResetDescriptors();
            .
            .
            .
            // here I add columns to the grid dynamically
 
                // NavbarNode contains information on where to load data from and how to display it
            i = 0;
            foreach (var col in NavbarNode.Columns)
            {
                GridViewDataColumn column = new GridViewDataColumn();
  
                column.Header = col.HeaderTitle;
                column.CellTemplate = CellTemplateList[i];
                column.MinWidth = col.MinWidth;
  
                ConfigureColumnDataBinding(i, col, column);
  
                GridView.Columns.Add(column);
                i++;
            }
            .
            .
            .
          
//
//
        private void ConfigureColumnDataBinding(int columnIndex, ColumnInfo col, GridViewDataColumn column)
        {
            column.DataMemberBinding = new System.Windows.Data.Binding("<Member path>");
            ConfigureColumnSorting(columnIndex, col, column);
            ConfigureColumnGrouping(columnIndex, col, column);            /* this function follows the same paradigm as the configure coumn sorting function */
        }
          
  
        private void ConfigureColumnSorting(int columnIndex, ColumnInfo col, GridViewDataColumn column)
        {
            column.IsSortable = true;
  
            if (NavbarNode.SortInfo != null)
            {
                var srtc = from sc in NavbarNode.SortInfo
                           where (sc.ColumnIndex - 1) == columnIndex
                           select sc;
  
                int CountOfSortColumns = srtc.Count();
  
                if (CountOfSortColumns > 0)
                {
                    if (CountOfSortColumns > 1)
                    {
                        throw new InvalidOperationException("Cannot have more than one sort column reference to a single column.");
                    }
                    else
                    {
                        SortColumn srtcol = srtc.Single();
                        // Add a sort descriptor
                        SortDescriptor sd = new SortDescriptor();
                        sd.Member = "<Member path>";
                        sd.SortDirection = (srtcol.SortDirection == SortDirection.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);
                        GridView.SortDescriptors.Add(sd);
                    }
                }
            }
        }
  
//
// Here I have to add exception swallowing code because I get exceptions a lot of times when I clear the group descriptors
        private void ResetDescriptors()
        {
            try
            {
                if (GridView.GroupDescriptors != null && GridView.GroupDescriptors.Count > 0)
                {
                    GridView.GroupDescriptors.Clear();
                }
            }
            catch (Exception ex) { }
            try
            {
                if (GridView.SortDescriptors != null && GridView.SortDescriptors.Count > 0)
                {
                    GridView.SortDescriptors.Clear();
                }
            }
            catch (Exception ex) { }
        }
0
Dimitrina
Telerik team
answered on 31 May 2011, 08:37 AM
Hello Rupendra,

 I have tested your scenario that the Sort indicator is not visible. I could reproduce this behavior on the second time when I apply Sorting without clearing the SortDescriptors already added. From the snippet of code that you have provided I can see that you call the ResetDescriptors() method, but I am not sure if you call it before every user click on a navigation bar item.

I have prepared a sample project where you may review how I have test. As well you may see that it is working alright when I call ResetDescriptors().

If you cannot get the Sorting indicator show appropriately, could you please change my project so that it has the wrong behavior. This way we could investigate it further.

Regards,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rupendra
Top achievements
Rank 1
answered on 31 May 2011, 04:30 PM
Hello,

Please see support ticket at http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=429728. I will post the description below again.

==========================
Hello Didie,

1. Yes, I call ResetDescriptors every time the user clicks on the navigation bar item.
2. Please find the attached solution. I have changed the sort order of the columns depending on the column index but you will notice that it only shows all columns sorted in one direction.

0
Dimitrina
Telerik team
answered on 01 Jun 2011, 04:19 PM
Hello Rupendra,

I have posted an answer to the support ticket that you have opened. It would be better to continue our dialogue via support tickets.

I am closing this forum thread now. Thank you.

All the best,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Peter
Top achievements
Rank 1
answered on 07 Nov 2013, 06:01 PM
I am having this same issue...

I am building a grid in code.  Adding my columns.  Adding my data. 

When I add the sorts or filters, the grid values are changed as expected; however, the grid UI does not ever indicate what the sorts or filters are if I set them from code.  I am setting everything in the datacontextchanged event.

I would like to know more about what was happening with this but I cannot see what is in the support ticket.

Was there ever a resolution?  Is there some method I can call on the grid to get the indicators to display if they are set in code?
0
Yordanka
Telerik team
answered on 08 Nov 2013, 06:53 AM
Hello Peter,

I would recommend you to check Programmatic Sorting and Programmatic Filtering help topics. Let me know if you have additional questions.
 
Regards,
Yordanka
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Peter
Top achievements
Rank 1
answered on 11 Nov 2013, 02:29 PM
I had read all that before. 

I re read it all again and still do not see any indication that there is a way to update the UI to show that I have changed the filters or sorts programatically. 

Am I correct in that conclusion that the UI does not at this time ever know that the SortDescriptors collection was modified unless the collection was modified because the header was clicked?

What I NEED is for the sorting to be set in code and then the header to be updated to show the sorting.  From all I read, it does not seem that the code allows that at this time.
0
Yordanka
Telerik team
answered on 13 Nov 2013, 08:21 AM
Hello Peter,

I am attaching a working demo. Please give it a try and let me know if you have additional questions.
 
Regards,
Yordanka
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Rupendra
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rupendra
Top achievements
Rank 1
Dimitrina
Telerik team
Peter
Top achievements
Rank 1
Yordanka
Telerik team
Share this question
or