/// <summary> /// Refreshes the slicer cache's values. /// </summary> internal void Refresh(ExcelPivotCacheDefinition cacheDefinition, List <CacheItem> previouslySelectedItems) { // If all are selected and a new value is added, it is selected. // Otherwise new values are added as deselected. bool isFiltered = this.TabularDataNode.Items.Any(i => !i.IsSelected); var cacheFieldIndex = cacheDefinition.GetCacheFieldIndex(this.SourceName); var cacheField = cacheDefinition.CacheFields[cacheFieldIndex]; var cacheItems = cacheDefinition.GetCacheItemsForSlicer(cacheField); this.TabularDataNode.Items.Clear(); if (isFiltered) { for (int i = 0; i < cacheItems.Count; i++) { var sharedItem = cacheItems[i]; bool isSelected = previouslySelectedItems.Any(si => si.Value == sharedItem.Value && si.Type == sharedItem.Type); this.TabularDataNode.Items.Add(i, isSelected); } } else { cacheItems.ForEach((c, i) => this.TabularDataNode.Items.Add(i, true)); } }
/// <summary> /// Applies the sort and hide settings to the slice values. This must be called after /// pivot tables are refreshed in order to work properly. /// </summary> /// <param name="cacheDefinition">The backing cache definition.</param> internal void ApplySettings(ExcelPivotCacheDefinition cacheDefinition) { var cacheFieldIndex = cacheDefinition.GetCacheFieldIndex(this.SourceName); var cacheField = cacheDefinition.CacheFields[cacheFieldIndex]; var cacheItems = cacheDefinition.GetCacheItemsForSlicer(cacheField); var sortedItems = this.Sort(cacheField, cacheItems); sortedItems = this.ApplyNoDataSettings(sortedItems, cacheDefinition, cacheFieldIndex, cacheField, cacheItems); this.TabularDataNode.Items.Clear(); this.TabularDataNode.Items.AddRange(sortedItems); }