We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to filter level elements from slicer axis through code behind?

Platform: jQuery |
Control: ejPivotClient
Tags: asp, js, mvc, pivotclient

This KB illustrates that how to filter level elements from slicer axis through code behind.

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.

JavaScript- https://help.syncfusion.com/js/pivotclient/olap-getting-started#creating-a-simple-application-with-pivot-client-and-olap-data-source-server-mode

ASP- https://help.syncfusion.com/aspnet/pivotclient/olap-getting-started#creating-a-simple-application-pivot-client-and-olap-data-sources-server-mode

MVC- https://help.syncfusion.com/aspnetmvc/pivotclient/olap-getting-started#creating-a-simple-application-with-pivotclient-and-olap-datasource-server-mode

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;
}

 

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile