Programmatically Sorting doesn't update sorting indicator

10 posts, 0 answers
  1. Rupendra
    Rupendra avatar
    8 posts
    Member since:
    May 2011

    Posted 26 May 2011 Link to this post

    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.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 May 2011 Link to this post

    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
  3. DevCraft banner
  4. Rupendra
    Rupendra avatar
    8 posts
    Member since:
    May 2011

    Posted 27 May 2011 Link to this post

    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) { }
            }
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 31 May 2011 Link to this post

    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
  6. Rupendra
    Rupendra avatar
    8 posts
    Member since:
    May 2011

    Posted 31 May 2011 Link to this post

    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.

  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 01 Jun 2011 Link to this post

    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
  8. Peter
    Peter avatar
    4 posts
    Member since:
    Feb 2013

    Posted 07 Nov 2013 Link to this post

    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?
  9. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 08 Nov 2013 Link to this post

    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 >>
  10. Peter
    Peter avatar
    4 posts
    Member since:
    Feb 2013

    Posted 11 Nov 2013 Link to this post

    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.
  11. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 13 Nov 2013 Link to this post

    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 >>
Back to Top
DevCraft banner