PivotGrid finished updating

4 posts, 0 answers
  1. Sandro
    Sandro avatar
    2 posts
    Member since:
    Feb 2016

    Posted 21 Feb Link to this post

    Hello!

    I am trying to retrieve the content of the PivotGrid to CSV format and I am using CsvFormatProvider.Export method for that.

    The PivotGrid is populated using LocalDataSourceProvider that is bounded to an ObservableCollection.

    The problem I am experiencing is that after updating the collection, the pivot table doesn't immediately reflect the new data, and therefore I can't manipulate the grid's content. I was trying to find an event that is raised after the Pivot Table is updated (I guess then the IsBusy property of PivotGrid is false), but couldn't find one. 

    I have tried "Loaded" and "Initialized" events of Pivot Table but none of them are raised after the Table is updated.

    So, can you please tell me how can I know when is the new data seen in the Pivot Table?

    I want to be able to retrieve the content of the grid in CSV format right after updating the ObservableCollection of the LocalDataSourceProvider.

     

    Thank you in advance,

    Sincerely,

    Alexander

  2. Polya
    Admin
    Polya avatar
    200 posts

    Posted 23 Feb Link to this post

    Hello Sandro,

    The LocalDataSourceProvider.ItemsSource property does not notify for collection changed. You can use any Collection that implements IEnumerable interface as ItemsSource. It is not mandatory that it is an ObservableCollection.

    If you wish to refresh the ItemsSource of the LocalDataSourceProvider whenever the ObservableCollection changes you should first set it to null and then to the new value. Setting the ItemsSource to null will cause clearing the engine and then when the new ItemsSource is set the engine can reinitialize with the correct data:
    var collection = new ObservableCollection<Order>();
    collection.CollectionChanged += collection_CollectionChanged;
      
    LocalDataSourceProvider localDataProvider = new LocalDataSourceProvider();
    localDataProvider.ItemsSource = collection;
      
    private void collection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        ObservableCollection<Order> obsSender = sender as ObservableCollection<Order>;
          
        // reset
        localDataProvider.ItemsSource = null;
        localDataProvider = new ObservableCollection<Order>(obsSender);
    }

    Hope this helps.

    Regards,
    Polya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sandro
    Sandro avatar
    2 posts
    Member since:
    Feb 2016

    Posted 24 Feb in reply to Polya Link to this post

    Hello Polya.

    I tried what you have propose but unfortunately this doesn't help.

    I would appreciate if you can help me with this.

    I don't think the problem is with the refreshing the ItemsSource of the LocalDataSourceProvider.

    I will try to explain myself better.

    Suppose you have a pivot table and a refresh button. The button executes command which gathers new data for the LocalDataSourceProvider's ItemsSource and the pivotTable shows all the content as expected. All good by now.

    I want to make CSV from the pivotGrid content. According to your tutorial - first I make a Workbook out of the PivotTable (GenerateWorkbook), and then I use CSVformatProvider.Export(workbook) method.

    My problem is as follows:

    I need that the same refresh command will make a CSV from the pivotGrid content. I want my viewModel to have a string property which contains the CSV of the pivotTable.

    I succeeded to make it in 2 steps: 1- Refresh button - to make the Pivot table. 2 - One more button to make the CSV from the current Table. But it is crucial for me to manage this only by refreshing the table.  But if I try to make a Workbook out of the PivotTable right after setting new Data to the provider, and before the PivotGrid is actually drawn, the GenerateWorkbook(pivotTable) function fails e.i. the table has zero rowCount and zero ColumnCount.

    So how would you generate the CSV from the PivotGrid?

    Thanks in advance,

    Sandro

     

         

  5. Polya
    Admin
    Polya avatar
    200 posts

    Posted 25 Feb Link to this post

    Hi Sandro,

    I suggest using the DataProvider.StatusChanged event and call the GenerateWorkbook(pivotTable) method when the provider had refreshed its ItemsSource and is done with the processing of the new source:
    public MainWindow()
    {
        InitializeComponent();
        var provider = this.Resources["DataProvider"] as LocalDataSourceProvider;
        provider.StatusChanged += provider_StatusChanged;
    }
     
    private void provider_StatusChanged(object sender, DataProviderStatusChangedEventArgs e)
    {
        if (e.OldStatus == DataProviderStatus.RetrievingData && e.NewStatus == DataProviderStatus.Ready)
        {
            //call GenerateWorkbook(pivotTable);
        }
    }

    Please give it a try and let us know whether it works for you.

    Regards,
    Polya
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top