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

Cannot Sort Column however other columns work and DataMemberBinding is set

7 Answers 506 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 23 Sep 2011, 02:35 PM
Hello,
I have a gridview that has a column that needs sorting. Every column that I want to sort does sort except one. The gridview's ItemsSource is an ICollectionView.


<telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn Header="My Overrides"
                                IsSortable="True"
                                SortMemberPath="Overrides"
                                DataMemberBinding="{Binding HasOverrides}"><!-- DOES NOT SORT-->
        <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <Button x:Name="ViewButtonOverrides"
                        Click="ShowOverridePrompt"
                        Cursor="Hand"
                        Content="My Overrides"
                        IsEnabled="{Binding HasOverrides}" />
            </DataTemplate>
        </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>
    <telerik:GridViewDataColumn Header="TicketStatus"
                                x:Name="TicketStatus"
                                SortMemberPath="TicketStatus.TicketStatusID"><!-- SORTS FINE -->
        <telerik:GridViewDataColumn.HeaderCellStyle>
            <Style TargetType="telerik:GridViewHeaderCell">
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <CheckBox x:Uid="CheckBox_11"
                                          Grid.Row="0"
                                          Grid.Column="0"
                                          Checked="CheckBox_TicketStatusesOnChecked"
                                          Unchecked="CheckBox_TicketStatusesOnUnchecked"
                                          IsChecked="False"
                                          DataContext="{Binding DataContext, ElementName=LayoutRoot}"
                                          Visibility="{Binding TicketStatusVisiblity, Mode=TwoWay}" />
                                <TextBlock Margin="0,0,0,-1"
                                           TextWrapping="Wrap"
                                           Text="Ticket Status"
                                           d:LayoutOverrides="Width, Height"
                                           Foreground="#FF4C607A" />
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </telerik:GridViewDataColumn.HeaderCellStyle>
        <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <Grid x:Uid="Grid_6">
                    <Grid.RowDefinitions>
                        <RowDefinition x:Uid="RowDefinition_22_1"
                                       Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition x:Uid="ColumnDefinition_8_1"
                                          Width="20" />
                        <ColumnDefinition x:Uid="ColumnDefinition_9_1"
                                          Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <CheckBox x:Uid="CheckBox_2"
                              Visibility="{Binding TicketStatusHasVisiblity, Mode=TwoWay}"
                              Grid.Row="0"
                              Grid.Column="0"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Bottom"
                              IsChecked="{Binding TicketStatusSelected, Mode=TwoWay}"
                              Checked="CheckBox_TicketStatusOnChecked"
                              Unchecked="CheckBox_TicketStatusOnUnchecked"
                              AutomationProperties.AutomationId="CheckBox_2" />
                    <Image x:Uid="Image_5"
                           Grid.Row="0"
                           Grid.Column="0"
                           Height="12"
                           Width="12"
                           Visibility="{Binding TicketStatusImageHasVisiblity, Mode=TwoWay}"
                           Source="{Binding TicketStatusImagePath}" />
                    <TextBlock x:Uid="TextBlock_1"
                               Grid.Row="0"
                               Grid.Column="2"
                               TextWrapping="Wrap"
                               VerticalAlignment="Bottom"
                               Text="{Binding TicketStatus, Mode=TwoWay}"
                               AutomationProperties.AutomationId="TextBlock_1" />
                </Grid>
            </DataTemplate>
        </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding MasterID}"
                                SortMemberPath="MasterID"
                                Header="ID"
                                IsReadOnly="True" /><!-- SORTS FINE -->
</telerik:RadGridView.Columns>

Please help me figure out why the "My Overrides" is not sorting.

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 27 Sep 2011, 03:50 PM
Hi Tyler,

 In order to have the column Sorting working you should provide a valid sort path for the specified column( SortMemberPath=[Valid sort path] ).

 In your case you use:

<telerik:GridViewDataColumn Header="My Overrides"
                               IsSortable="True"
                               SortMemberPath="Overrides"
                               DataMemberBinding="{Binding HasOverrides}"><!-- DOES NOT SORT-->

How is the 'Overrides' object defined? Is it sortable?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Tyler
Top achievements
Rank 1
answered on 27 Sep 2011, 04:17 PM
Ah ha, the 'Overrides' object was a List of overrides and therefore not itself sortable. I have now set the sort item to "HasOverrides" which is sortable. Thank you very much for your assistance.
0
Jonathon
Top achievements
Rank 1
answered on 13 Oct 2011, 01:35 AM
Hi,

I am having the same problem, however,I was not able to get it fixed. Here is my RadGridView:

<telerik:RadGridView 
                                RowStyleSelector="{StaticResource isCompletedTaskStyle}"
                                GridLinesVisibility="Both"
                                SelectedItem="{Binding SelectedTask, Mode=TwoWay}"
                                IsReadOnly="True"
                                IsFilteringAllowed="False"
                                AutoGenerateColumns="False"
                                BorderThickness="1"
                                BorderBrush="LightGray"
                                CanUserFreezeColumns="False"
                                ShowGroupPanel="False"
                                RowIndicatorVisibility="Collapsed"
                                ItemsSource="{Binding Tasks}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewImageColumn IsReadOnly="True" IsSortable="True" DataMemberBinding="{Binding ActivityType,Converter={StaticResource DocTypeToBitmap}}" ImageHeight="20" ImageWidth="20" Header="Task" />
                    <telerik:GridViewDataColumn IsReadOnly="True" IsSortable="True" SortMemberPath="Subject"  DataMemberBinding="{Binding Subject}" Header="Subject" />
                    <telerik:GridViewDataColumn IsReadOnly="True"  DataMemberBinding="{Binding Owner.Name}" Header="From"/>
                    <telerik:GridViewDataColumn IsReadOnly="True"  DataMemberBinding="{Binding StartTime}" Header="Date Created"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

I am unable to sort Subject which is just a string. The Tasks are an ObservableCollection<ITask>.

Thanks,

Jonathon
0
Vlad
Telerik team
answered on 13 Oct 2011, 06:49 AM
Hello Jonathon,

 Can you post more info about your grid version? Can you try to set DataType for this column?

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jonathon
Top achievements
Rank 1
answered on 13 Oct 2011, 11:40 PM
Where do I see info about my grid version? Also in the code behind, I know I write:
var column = this.radGridView1.Columns["SomeColumn"] as GridViewBoundColumnBase;
if (column != null)
{
column.DataType = typeof(string);
}

Is "SomeColumn" a name given to the column like x:Name or is it the header or UniqueName?

Thanks,

Jonathon
0
Jonathon
Top achievements
Rank 1
answered on 01 Nov 2011, 08:01 PM
Sorry I haven't replied in a while, however, I've come back to this issue and still have no resolution. I have already posted my code in a previous comment. Anyone have any ideas?

Thanks,
Jonathon
0
Maya
Telerik team
answered on 02 Nov 2011, 07:02 AM
Hello Jonathon,

I will recommend you to run through our online documentation so that you get more profound idea about how to define columns, how to get them from the Columns collection either with its index, or with its UniqueName. 
 

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Tyler
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Tyler
Top achievements
Rank 1
Jonathon
Top achievements
Rank 1
Vlad
Telerik team
Maya
Telerik team
Share this question
or