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

Pivot table doesn't update after ItemsSource changed in ViewModel

2 Answers 214 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
guobian
Top achievements
Rank 1
guobian asked on 12 Feb 2014, 05:51 PM
Hi,

I am using MVVM pattern to build a Pivot table per user's request. Because of the MVVM pattern, I define the LocalDataSourceProvider for the pivot grid and assign its ItemsSource in the ViewModel. My issue is that the pivot is showing the data that was assigned to the ItemsSource first time. E.g.: When I bind the the ItemsSource to my list on first time, the Pivot is showing the correct data on screen. After that, no matter how I change the ItemsSource, the Pivot is always showing the data assinged on the first assignment.

Here is the code that relate to the issue.

In xaml:
                    <pivot:RadPivotGrid x:Name="pivot1" Grid.Column="0" DataProvider="{Binding DataSource}"  
                                          VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5"
                                        UseLayoutRounding="False" d:LayoutRounding="Auto" FontSize="10" >
                    </pivot:RadPivotGrid>

                    <pivot:RadPivotFieldList Grid.Column="1" DataProvider="{Binding DataSource}" Margin="-1,0,1,0" FontSize="10" />

In ViewModel:
        private LocalDataSourceProvider _dataSource;
        public LocalDataSourceProvider DataSource
        {
            get { return _dataSource; }
            set
            {
                _dataSource = value;
                RaisePropertyChanged("DataSource");
            }
        }

        private void InitialDataSource()
        {
            _dataSource = new LocalDataSourceProvider();
            _dataSource.RowGroupDescriptions.Add(new PropertyGroupDescription { PropertyName = "ProductType" });
            _dataSource.RowGroupDescriptions.Add(new PropertyGroupDescription { PropertyName = "CashType" });

            _dataSource.ColumnGroupDescriptions.Add(new DateTimeGroupDescription { PropertyName = "ValueDate",Step=DateTimeStep.Day});
            _dataSource.AggregateDescriptions.Add(new PropertyAggregateDescription { PropertyName = "Value", StringFormat = "#,#; -#,#" });
        }

        private void GetDataSource()
        {
            DataSource.ItemsSource = _reports;

            RaisePropertyChanged("DataSource");
        }

A button click event will trigger re-assignment of the _reports and calls the GetDataSource function.

Please take a look and let me know how I can correct.

Many thanks,
guobian

2 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 13 Feb 2014, 10:01 AM
Hello Guobian,

In order to refresh the ItemsSource of the LocalDataSourceProvider you will firstly need to set the ItemsSource to null and then to the required collection:

private void GetDataSource()
{
    DataSource.ItemsSource = null;
    DataSource.ItemsSource = _reports;
 
    RaisePropertyChanged("DataSource");
}

Hope this helps.

Regards,
Kalin
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

0
guobian
Top achievements
Rank 1
answered on 13 Feb 2014, 11:48 AM
Hi Kalin,

Issue resolved by setting the ItemsSource to null first.

Thanks very much for the quick reply.

Regards,
guobian
Tags
PivotGrid
Asked by
guobian
Top achievements
Rank 1
Answers by
Kalin
Telerik team
guobian
Top achievements
Rank 1
Share this question
or