Pivot table doesn't update after ItemsSource changed in ViewModel

3 posts, 0 answers
  1. guobian
    guobian avatar
    5 posts
    Member since:
    Aug 2011

    Posted 12 Feb 2014 Link to this post

    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. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 13 Feb 2014 Link to this post

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. guobian
    guobian avatar
    5 posts
    Member since:
    Aug 2011

    Posted 13 Feb 2014 in reply to Kalin Link to this post

    Hi Kalin,

    Issue resolved by setting the ItemsSource to null first.

    Thanks very much for the quick reply.

    Regards,
    guobian
Back to Top