How to Sort Grid by a hidden column (by default)

9 posts, 1 answers
  1. Clarian Villamayor
    Clarian Villamayor avatar
    13 posts
    Member since:
    Jun 2010

    Posted 07 Sep 2012 Link to this post

    Hi,

    I have a grid that I want to sort by "Sequence" property by default.
    However, this should not be visible to user. 

    <control:RadGridView ="grid" >
    <control:RadGridView.SortDescriptors>
    <telerik:SortDescriptor Member="Sequence" SortDirection="Ascending" />
    </control:RadGridView.SortDescriptors>

    <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn Header="Sequence" DataMemberBinding="{Binding Sequence}" IsReadOnly="True" IsVisible="False"/>
    <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"/> 
    ...

    User should only see the "Name" column while sorted by sequence.

    Apparently, the sort only works when the sequence column IsVisible=True

    Is it possible to hide it and sort as the same time?

    Thanks,
    Clarian
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Sep 2012 Link to this post

    Hi,

    In order to have the column being Sorted on Sequence values, you should provide a valid sort path for it ( SortMemberPath="Sequence"). 

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Clarian Villamayor
    Clarian Villamayor avatar
    13 posts
    Member since:
    Jun 2010

    Posted 07 Sep 2012 Link to this post

    Thanks, Didie,

    Should I add it to the Name column? (With that I can remove the Sequence column?)
    What should my code above be?


  5. Clarian Villamayor
    Clarian Villamayor avatar
    13 posts
    Member since:
    Jun 2010

    Posted 07 Sep 2012 Link to this post

    Found this to work. Thanks

    <control:RadGridView ="grid" >
    <control:RadGridView.SortDescriptors>
    <telerik:SortDescriptor Member="Name" SortDirection="Ascending" />
    </control:RadGridView.SortDescriptors>

    <telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}" SortMemberPath="Sequence"/>  
  6. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Sep 2012 Link to this post

    Hello,

    Thank you for the update. This code will do sorting based on the Name values. If you want to sort on the Sequence values, you have to set Member="Sequence". That way you will not have a Sorting Indicator on the GridViewHeaderCell though.

    To have the indicator, you should use a ColumnSortDescriptor instead:

    <telerik:RadGridView.SortDescriptors>
    <telerik:ColumnSortDescriptor Column="{Binding Columns[\Name\], ElementName=clubsGrid}" SortDirection="Ascending" />
    </telerik:RadGridView.SortDescriptors>

    I hope this helps.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Clarian Villamayor
    Clarian Villamayor avatar
    13 posts
    Member since:
    Jun 2010

    Posted 24 Sep 2012 Link to this post

    Hi -- How can I do this programatically/dynamically, such that the Sorting Indicator will be hidden?
    
                _nameSort = new ColumnSortDescriptor()
                {
                    Column = this.grid.Columns["Name"],
                    SortDirection = System.ComponentModel.ListSortDirection.Ascending
                };
                this.grid.SortDescriptors.Add(_nameSort); Thanks!
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Sep 2012 Link to this post

    Hello,

     You could set the SortingState of the Column to be None. For example:

    _nameSort.Column.SortingState = SortingState.None;

    Kind regards,
    Didie
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  9. Clarian Villamayor
    Clarian Villamayor avatar
    13 posts
    Member since:
    Jun 2010

    Posted 24 Sep 2012 Link to this post

    I tried it but the sort indicator (little triangle on the header) still shows.
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Sep 2012 Link to this post

    Hello,

    You should add this line after you have added the descriptor to the SortDesriptors collection.

    Regards,
    Didie
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Back to Top
DevCraft banner