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

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

8 Answers 369 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Clarian Villamayor
Top achievements
Rank 1
Clarian Villamayor asked on 07 Sep 2012, 10:07 AM
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

8 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 07 Sep 2012, 10:13 AM
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.

0
Clarian Villamayor
Top achievements
Rank 1
answered on 07 Sep 2012, 10:38 AM
Thanks, Didie,

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


0
Clarian Villamayor
Top achievements
Rank 1
answered on 07 Sep 2012, 12:39 PM
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"/>  
0
Accepted
Dimitrina
Telerik team
answered on 07 Sep 2012, 01:25 PM
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.

0
Clarian Villamayor
Top achievements
Rank 1
answered on 24 Sep 2012, 09:23 AM
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!
0
Dimitrina
Telerik team
answered on 24 Sep 2012, 09:32 AM
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.

0
Clarian Villamayor
Top achievements
Rank 1
answered on 24 Sep 2012, 10:58 AM
I tried it but the sort indicator (little triangle on the header) still shows.
0
Dimitrina
Telerik team
answered on 24 Sep 2012, 03:30 PM
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.

Tags
GridView
Asked by
Clarian Villamayor
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Clarian Villamayor
Top achievements
Rank 1
Share this question
or