Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3160
How do I refresh a pivot grid?
posted

Well today is my day to fight with a XamPivotGrid.

So I got my grid to reload data and the new data appears in the dropdown filter selectors but it does not appear in the pivot grid itself.  When I filter and select the new data only the pivot grid shows no items.  How do I fix this?  The code blow is called in the loaded event of the grid and when the user clicks the refresh button.

thank you,

Sam

private void ExposureGrid_Loaded(object sender, RoutedEventArgs e)
{
 ExposureGrid.Loaded -= ExposureGrid_Loaded;

 Refresh();
}

private void Refresh()

{
 var x = ViewModel.GetExposureItems();
 ExposureGrid.DataSource = (IOlapViewModel)FindResource("FlatData");

 if (ExposureGrid.DataSource.Filters.Count > 0)
  ExposureGrid.DataSource.Filters.Clear();

 FilterHelper = new XAMPivotFilterHelper<ExposureItem> { FlatDataSource = ((FlatDataSource)ExposureGrid.DataSource) };
 FilterHelper.FlatDataSource.ItemsSource = x;

 ExposureGrid.DataSource.Filters.Add(ExposureGrid.DataSource.CreateFilterViewModel(
 ExposureGrid.DataSource.Cube.Dimensions["PM_Name"].Hierarchies.First()));

 ExposureGrid.DataSource.Filters.Add(ExposureGrid.DataSource.CreateFilterViewModel(
  ExposureGrid.DataSource.Cube.Dimensions["DeliveryDate"].Hierarchies.First()));

 ExposureGrid.DataSource.Filters.Add(ExposureGrid.DataSource.CreateFilterViewModel(
  ExposureGrid.DataSource.Cube.Dimensions["IsFail"].Hierarchies.First()));

 FilterHelper.FilterOption("DeliveryDate", "All", false);
 FilterHelper.FilterOption("IsFail", "All", false);
 FilterHelper.FilterOption("IsFail", "N/A", true);
 OnDeliveryChanged(this, new EventArgs());
 OnPMFilterChanged(this, new EventArgs());
 chkIsNetFails_Click(this, new RoutedEventArgs());
 ExposureGrid.DataSource.ResultChanged += FilterHelper.OnResultChanged;
 ExposureGrid.DataSource.RefreshGrid();
}
}

 

Parents
No Data
Reply
  • 8831
    Verified Answer
    posted

    Hello Sam,

    I see that every time when Refresh() is called you have the same data source and you have added all filter view model instances to IOlapViewModel.Filters collection, so I suppose all this is about a functionality that should only change the filters you have applied and then it's supposed that the grid should display the data related to the modified filters.

    It's good before to call DataSource.Filters.Clear() to set DataSource.DeferredLayoutUpdate to true. When you finish with the filters modification setting DataSource.DeferredLayoutUpdate back to false will refresh the data automatically; you don't need to call DataSource.RefreshGrid(). That will work in cases where you have added new filter view model instances, just like you do.

    Another way to get the result updated is to call DataSource.UpdateVisualMembers(Olap.ExecutionContext) for both Rows and Columns and call DataSource.RefreshGrid() then. This is more applicable when you haven't modified the Filters collection but just filters state.

    Let me know about your progress with that and also if you have any further questions.

    Regards.
    Plamen.

Children
No Data