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

[Solved] Broken Sorting Functionality

12 Answers 239 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.
Kathleen
Top achievements
Rank 1
Kathleen asked on 31 Jan 2011, 06:01 PM
Last week we upgraded solution to Silverlight4_2010_3_1314.

Prior to that we were using 2010.2.0924.1040.

We have a customized Grid Control, inherited from RadGridView that handles some of the extended functionality we needed like custom filter controls etc.  This is displayed with a Data Pager and bound to a ViewModel.

Binding looks something like this:

<telerikControls:RadDataPager PageSize="{Binding Source={StaticResource personalizationProvider}, 
                                            Path=PreferenceModel.GridDefaults.PageSize}"
                                  Source="{Binding DomainDataSource.Data}"
                                  DisplayMode="FirstLastPreviousNextNumeric, Text" 
                                  IsTotalItemCountFixed="True"
                                  HorizontalAlignment="Stretch"
                                  Visibility="{Binding PageCount, Converter={StaticResource dataPagerVisibilityConverter}}"
                                  Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" />
    <StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" 
                HorizontalAlignment="Center" VerticalAlignment="Center"
                Orientation="Horizontal"
                Visibility="{Binding Path=DomainDataSource.DataView.TotalItemCount, Converter={StaticResource countGreaterThanToVisibilityConverter}, ConverterParameter=0}">
        <TextBlock Text="{Binding Path=DomainDataSource.DataView.Count}" />
        <TextBlock Text="{Binding Path=Common.LowerCaseOfSurroundedBySpaces, Source={StaticResource Strings}}" />
        <TextBlock Text="{Binding Path=DomainDataSource.DataView.TotalItemCount}" />
        <TextBlock Text=" " />
        <TextBlock Text="{Binding Path=CaptionManager.PluralName}" />
    </StackPanel>
    <presentationControls:CustomDataGrid 
        Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"            
        SelectionMode="Single"
        x:Name="gridView"
        TabIndex="0"
        TabNavigation="Once"
        IsTabStop="True"
        IsReadOnly="True"   
        ItemsSource="{Binding Collection}"            
        IsBusy="{Binding Path=BusyIndicator.IsBusy}"
        SelectedItem="{Binding Selection, Mode=TwoWay}"
        AutoGenerateColumns="True"
        CanUserDeleteRows="False" 
        CanUserInsertRows="False" 
        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" 
        ShowGroupPanel="False" 
        GridLinesVisibility="Horizontal" 
        ActionOnLostFocus="None" 
        DataLoadMode="Synchronous" CanUserFreezeColumns="False"
        RowIndicatorVisibility="Collapsed"
        DomainDataSource="{Binding Path=DomainDataSource}"
        CollectionViewModel="{Binding}"
        >
        <telerikGridView:RadGridView.Columns>
            <telerikGridView:GridViewSelectColumn Header="Inc?" x:Name="MultiSelectColumn" IsVisible="False" IsReorderable="False"/>
            <telerikGridView:GridViewColumn Header="{Binding Source={StaticResource StringResource},Path=Common.HeaderName}"
                                            IsReorderable="False"
                                            CellTemplate="{StaticResource cellTemplate}" />
        </telerikGridView:RadGridView.Columns>
        <i:Interaction.Behaviors>
            <presentationBehaviors:PersistentRadGridBehavior />
            <presentationBehaviors:RadGridViewMultiSelectionBehavior SelectedItems="{Binding SelectedItems, Mode=TwoWay}"/>
            <presentationBehaviors:FocusBehavior />
            <presentationBehaviors:ContextMenuBehavior />
        </i:Interaction.Behaviors>
    </presentationControls:CustomDataGrid>


Issue is, sorting the grid no longer triggers a data load.  Instead the column header sorts, but the data within it does not.  I have checked breaking changes, but didn't see anything to indicate why this has stopped functioning.

12 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 01 Feb 2011, 08:09 AM
Hello,

 Can you post more info about the collection bound to the grid? With out service pack we've fixed an issue related to ICollectionView and now the grid will not sort internally however will transfer the sort info to the collection if the collection itself can sort. 

Greetings,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Jeremy
Top achievements
Rank 1
answered on 01 Feb 2011, 12:49 PM
"we've fixed an issue related to ICollectionView and now the grid will not sort internally however will transfer the sort info to the collection if the collection itself can sort. "

How does the grid determine whether it should transfer the sort?  The grid's ItemsSource is bound to this property:

public IEnumerable Collection
{
    get
    {
        return this.DomainDataSource.DataView.Count == 0 ? new ObservableCollection<TCollectionEntity>() : this.DomainDataSource.Data;
    }
}

We're wrapping the domain data source's data property to workaround an issue where the column headers don't appear when the grid is empty because the DomainDataSource's data property is an empty data view.  This binding/code hase been working for at least 6 months, the comment about conditionally transferring the sort is making me wonder if this is the problem.

Thanks for your help,

-jd
0
Vlad
Telerik team
answered on 01 Feb 2011, 02:04 PM
Hello,

I'm not sure how this is related to the previous question? Do you have the same problem? The grid will check ICollectionView.CanSort to determine if the source collection can sort or not. 

Regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kathleen
Top achievements
Rank 1
answered on 01 Feb 2011, 02:38 PM
He was answering your direct question, telling you more about the Collection we are binding the grid too.

As he points out, this was working just fine the last 6 months (actually longer).   Is there documentation somewhere about this change and what we need to do to fix it?
0
Vlad
Telerik team
answered on 01 Feb 2011, 03:49 PM
Hi,

I've just tested this however everything worked fine on my end. You can check the attached example application for reference. 

Kind regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kathleen
Top achievements
Rank 1
answered on 01 Feb 2011, 05:04 PM
Your sample is binding your UI to the DomainContext.

We are using MVVM, we do not use it this way.

We  have a view model that exposes teh DomainContext.Data as a Collection.

As indicated, this has been funcitoning fine for actually almost a year, we need to understand what has changed so we can resolve this problem.
0
Vlad
Telerik team
answered on 01 Feb 2011, 05:08 PM
Hi,

 How exactly my approach is not MVVM? I've tried to recreate your scenario and to simulate the problem using the code posted from you and the other poster (maybe your colleague?). Please send us small runnable project (via support ticket) where we can recreate the problem.

Kind regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kathleen
Top achievements
Rank 1
answered on 01 Feb 2011, 05:26 PM
I didn't look at the sample enough, Jeremy caught how you replicated it.  He's investigating the variance to try and identify the problem in the sample.
0
Jeremy
Top achievements
Rank 1
answered on 11 Feb 2011, 05:53 PM

To reproduce our issue, update the sample project (SilverlightApplication1.zip above) with the following:

1) add a reference to telerik.windows.controls.data
2) replace MainPage.xaml with:

<UserControl 
    x:Class="SilverlightApplication1.MainPage"
    xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    xmlns:telerikDataControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Data"    
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
  
    <Grid x:Name="LayoutRoot" Background="White">
        <telerikGridView:RadGridView SelectionMode="Single"
            x:Name="gridView"
            TabIndex="0"
            TabNavigation="Once"
            IsTabStop="True"
            IsReadOnly="True"   
            ItemsSource="{Binding Collection}"            
            AutoGenerateColumns="True"
            CanUserDeleteRows="False" 
            CanUserInsertRows="False" 
            HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" 
            ShowGroupPanel="False" 
            GridLinesVisibility="Horizontal" 
            ActionOnLostFocus="None" 
            DataLoadMode="Synchronous" CanUserFreezeColumns="False"
            MaxWidth="4000" MaxHeight="4000" 
            RowIndicatorVisibility="Collapsed">
<!--
we use ItemsSource="{Binding Collection}" but ItemsSource="{Binding DomainDataSource.Data}" doesn't fix the issue either.
--> 
  
        </telerikGridView:RadGridView>
  
        <telerikDataControls:RadDataPager PageSize="5"
                                          Source="{Binding DomainDataSource.Data}"
                                          DisplayMode="FirstLastPreviousNextNumeric, Text"
                                          IsTotalItemCountFixed="True"
                                          HorizontalAlignment="Stretch" 
                                          VerticalAlignment="Bottom" />
  
  
    </Grid>
</UserControl>

3) replace mainpage.xaml.cs with:
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ServiceModel.DomainServices.Client;
using System.Windows.Controls;
using WebApplication1;
  
namespace SilverlightApplication1
{
    public partial class MainPage : UserControl, INotifyPropertyChanged
    {
        private NorthwindDomainContext domainContext;
  
        public MainPage()
        {
  
            this.DomainDataSource = new DomainDataSource();
            this.domainContext = new NorthwindDomainContext();
            this.DomainDataSource.DomainContext = domainContext;
            this.DomainDataSource.QueryName = "GetCustomersQuery";
            this.DomainDataSource.LoadingData += this.LoadingData;
            this.DomainDataSource.LoadedData += this.LoadedData;
            this.DomainDataSource.AutoLoad = false;
  
            this.DomainDataSource.SortDescriptors.Add(new SortDescriptor("ContactName", ListSortDirection.Ascending));
  
            InitializeComponent();
            this.DataContext = this;
  
            this.Loaded += (s, e) => { this.DomainDataSource.Load(); };
        }
  
        public IEnumerable Collection
        {
            get
            {
                return this.DomainDataSource.DataView.Count == 0 ? new ObservableCollection<Customer>() : this.DomainDataSource.Data;
            }
        }
  
        public DomainDataSource DomainDataSource { get; private set; }
  
        public event PropertyChangedEventHandler PropertyChanged;
  
        private void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
  
        private void LoadingData(object sender, LoadingDataEventArgs e)
        {
            e.LoadBehavior = LoadBehavior.MergeIntoCurrent;
        }
  
        private void LoadedData(object sender, LoadedDataEventArgs e)
        {
            if (!e.HasError)
            {
                if (this.DomainDataSource.DataView.PageIndex != -1
                   && !(this.DomainDataSource.DataView.PageIndex >= this.DomainDataSource.DataView.PageCount))
                {
                    this.OnPropertyChanged("Collection");
                }
            }
        }
    }
}

4) run the sln, click on the column headers to invoke sorting... nothing happens


Thanks for your help with this.

Jeremy Danyow
0
Kathleen
Top achievements
Rank 1
answered on 15 Feb 2011, 12:47 PM
Any movement on this now that we've provided an example?
0
hvduc
Top achievements
Rank 1
answered on 16 Feb 2011, 04:26 AM
I get this problem too. this happen after my application was update to Q3 SP1.
I found out problem lies in data type binded to gridview's itemssource.
If itemssource is binded from DomainDataSource.Data (datatype is IEnumerable), can't sort on grid. but if change data to list(of object), sort function still works.
In Q3 version, this problem isn't happen
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 16 Feb 2011, 05:39 PM
Hi Kathleen,

The result of my investigation is that MS DomainDataSource doesn't reload data when SortDescriptor's collection is changed. However you could use our RadDomainDataSource control. I'm attaching an example based on the code provided in your blog post using our control.
Let me know if this example doesn't meet your requirements.

P.S. If you insist using MS DomainDataSource you could handle SortDescriptors CollectionChanged event and call DomainDataSource.Load() method manually.

Best wishes,
Nedyalko Nikolov
the Telerik team
Tags
GridView
Asked by
Kathleen
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jeremy
Top achievements
Rank 1
Kathleen
Top achievements
Rank 1
Jeremy
Top achievements
Rank 1
hvduc
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or