Cannot Sort Column however other columns work and DataMemberBinding is set

8 posts, 0 answers
  1. Tyler
    Tyler avatar
    15 posts
    Member since:
    Dec 2010

    Posted 23 Sep 2011 Link to this post

    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.
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 27 Sep 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Tyler
    Tyler avatar
    15 posts
    Member since:
    Dec 2010

    Posted 27 Sep 2011 Link to this post

    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.
  5. Jonathon
    Jonathon avatar
    50 posts
    Member since:
    Aug 2011

    Posted 12 Oct 2011 Link to this post

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

    Posted 13 Oct 2011 Link to this post

    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 >>

  7. Jonathon
    Jonathon avatar
    50 posts
    Member since:
    Aug 2011

    Posted 13 Oct 2011 Link to this post

    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
  8. Jonathon
    Jonathon avatar
    50 posts
    Member since:
    Aug 2011

    Posted 01 Nov 2011 Link to this post

    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
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Nov 2011 Link to this post

    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 >>

Back to Top
DevCraft banner