How to filter level elements from slicer axis in JS Pivot Client?
This KB illustrates that how to filter level elements from slicer axis in JS Pivot Client.
Solution:
Follow the given steps to exclude the level elements with OLAP server mode in the slicer axis through code behind.
Step 1:
Create a project for pivot client through the following documentation link.
Step 2:
Add the following namespace to the pivot client Web API controller.
using Syncfusion.Olap.DataProvider;
Step 3:
In the pivot client Web API controller, you can use the “excludeElements” method to filter the level elements from the slicer axis.
public OlapDataManager excludeElements(OlapDataManager dataManager) { var slicerElements = dataManager.CurrentReport.SlicerElements; foreach (var sliceElement in slicerElements) { string uniqueName = (sliceElement.ElementValue as DimensionElement).Hierarchy.LevelElements[0].UniqueName; var memberCollection = (dataManager.DataProvider as Syncfusion.Olap.DataProvider.AdomdDataProvider).GetMembersUsingMDX(uniqueName, 0, 0, false, Syncfusion.Olap.DataProvider.NodeTypes.Parent); DimensionElement excludedColumnElement = new DimensionElement(); excludedColumnElement.Name = (sliceElement.ElementValue as DimensionElement).ElementName; excludedColumnElement.AddLevel((sliceElement.ElementValue as DimensionElement).Hierarchy.ElementName, (sliceElement.ElementValue as DimensionElement).Hierarchy.LevelElements[0].ElementName); for (var i = 0; i < memberCollection.Count; i++) { if (((sliceElement.ElementValue as DimensionElement).Hierarchy.LevelElements[0].MemberElements[0].UniqueName) != memberCollection[i].UniqueName) excludedColumnElement.Hierarchy.LevelElements[(sliceElement.ElementValue as DimensionElement).Hierarchy.LevelElements[0].ElementName].Add(new MemberElement { UniqueName = memberCollection[i].UniqueName }); } sliceElement.ExcludedElementValue = excludedColumnElement; } return dataManager; }
Step 4:
You can call the previous method through the “InitializeClient” method. Refer to the following code snippet.
[System.Web.Http.ActionName("InitializeClient")] [System.Web.Http.HttpPost] public Dictionary<string, object> InitializeClient(Dictionary<string, object> jsonResult) { OlapDataManager DataManager = null; //… DataManager.SetCurrentReport(CreateOlapReport((customData is Dictionary<string, object> && customData.ContainsKey("Report")) ? customData["Report"] : "", DataManager)); DataManager = excludeElements(DataManager); //… return report; }
Conclusion
I hope you enjoyed learning about how to filter level elements from slicer axis in JS Pivot Client.
You can refer to our JavaScript PivotGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript PivotGrid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!