Your requirement can be achieved by filtering the particular level members using Slicer elements in the OlapReport. Please find the sample code snippet that can be used to achieve the same by passing the “customObject” parameter.
function applyFilter(args) {
var PivotGridObj = $("#PivotGrid1").data("ejPivotGrid");
var PivotChartObj = $("#PivotChart1").data("ejPivotChart");
var levelUniqueName = args.selectedValue; // specify the selected level UniqueName
var customObj = JSON.stringify(levelUniqueName);
// Render PivotGrid
PivotGridObj.doAjaxPost("POST", "/OlapService/InitializeGrid", JSON.stringify({ "action": "initializeGrid", "gridLayout": PivotGridObj.layout(), "enablePivotFieldList": PivotGridObj.model.enablePivotFieldList, "customObject": customObj }), PivotGridObj._renderControlSuccess);
// Render PivotChart
PivotChartObj.doAjaxPost("POST", "/OlapService/InitializeChart", JSON.stringify({ "action": "initialize", "currentReport": PivotChartObj.model.currentReport, "customObject": customObj }), PivotChartObj.renderControlSuccess);
} |
public class OlapServiceController : ApiController
{
Syncfusion.JavaScript.PivotGrid htmlHelper = new Syncfusion.JavaScript.PivotGrid();
Syncfusion.JavaScript.PivotChart pivotChart = new Syncfusion.JavaScript.PivotChart();
string filteredReport = null;
string connectionString = "Data Source=http://bi.syncfusion.com/olap/msmdpump.dll; Initial Catalog=Adventure Works DW 2008 SE;";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string conStringforDB = ""; //Enter appropriate connection string to connect database for saving and loading operation of reports
[System.Web.Http.ActionName("InitializeGrid")]
[System.Web.Http.HttpPost]
public Dictionary<string, object> InitializeOlapGrid(Dictionary<string, object> jsonResult)
{
OlapDataManager DataManager = null;
dynamic customData = serializer.Deserialize<dynamic>(jsonResult["customObject"].ToString());
if (customData as string != null)
filteredReport = customData;
DataManager = new OlapDataManager(connectionString);
DataManager.SetCurrentReport(CreateOlapReport());
DataManager.OverrideDefaultFormatStrings = true;
return htmlHelper.GetJsonData(jsonResult["action"].ToString(), DataManager, jsonResult.ContainsKey("gridLayout") ? jsonResult["gridLayout"].ToString() : null, Convert.ToBoolean(jsonResult["enablePivotFieldList"].ToString()));
}
[System.Web.Http.ActionName("InitializeChart")]
[System.Web.Http.HttpPost]
public Dictionary<string, object> InitializeChart(Dictionary<string, object> jsonResult)
{
dynamic customData1 = serializer.Deserialize<dynamic>(jsonResult["customObject"].ToString());
if (customData1 as string != null)
filteredReport = customData1;
OlapDataManager DataManager = new OlapDataManager(connectionString);
DataManager.SetCurrentReport(CreateOlapReport());
return pivotChart.GetJsonData(jsonResult["action"].ToString(), DataManager);
}
//
//
private OlapReport CreateOlapReport()
{
OlapReport olapReport = new OlapReport();
olapReport.CurrentCubeName = "Adventure Works";
MeasureElements measureElement = new MeasureElements();
measureElement.Elements.Add(new MeasureElement { UniqueName = "[Measures].[Internet Sales Amount]" });
DimensionElement dimensionElementRow = new DimensionElement();
dimensionElementRow.Name = "Date";
dimensionElementRow.AddLevel("Fiscal", "Fiscal Year");
DimensionElement dimensionElementSlicer = new DimensionElement();
dimensionElementSlicer.Name = "Customer";
dimensionElementSlicer.AddLevel("Customer Geography", "Country");
if (filteredReport as string != null)
dimensionElementSlicer.Hierarchy.LevelElements["Country"].Add(new MemberElement() { UniqueName = filteredReport });
olapReport.SeriesElements.Add(dimensionElementRow);
olapReport.SlicerElements.Add(dimensionElementSlicer);
olapReport.CategoricalElements.Add(measureElement);
return olapReport;
}
}
} |
<style>
#groupingBarPivot>.drag>.pivotButton>.filter{
display: none;
}
</style> |
function applyFilter(args) {
var PivotGridObj = $("#PivotGrid1").data("ejPivotGrid");
var PivotChartObj = $("#PivotChart1").data("ejPivotChart");
var includelevelUniqueName = args.selectedValue; //filter element that you selected from the dropdownlist
var excludelevelUniqueName = []; //filter elements that are exclude from the dropdownlist
if (!ej.isNullOrUndefined($('#drpdwn').data("ejDropDownList")))
$.each($('#drpdwn').data("ejDropDownList")._rawList, function (e, item) { if (item.value.length > 0 && item.value != includelevelUniqueName) excludelevelUniqueName.push(item.value) });
var customObj = { "includedElements": includelevelUniqueName, "excludedElements": excludelevelUniqueName }
var serializedcustomObj = JSON.stringify(customObj);
// Render PivotGrid
PivotGridObj.doAjaxPost("POST", "/OlapService/InitializeGrid", JSON.stringify({ "action": "initializeGrid", "gridLayout": PivotGridObj.layout(), "enablePivotFieldList": PivotGridObj.model.enablePivotFieldList, "customObject": serializedcustomObj }), PivotGridObj._renderControlSuccess);
// Render PivotChart
PivotChartObj.doAjaxPost("POST", "/OlapService/InitializeChart", JSON.stringify({ "action": "initialize", "currentReport": PivotChartObj.model.currentReport, "customObject": serializedcustomObj }), PivotChartObj.renderControlSuccess);
} |
public class OlapServiceController : ApiController
{
Syncfusion.JavaScript.PivotGrid htmlHelper = new Syncfusion.JavaScript.PivotGrid();
Syncfusion.JavaScript.PivotChart pivotChart = new Syncfusion.JavaScript.PivotChart();
string includedElements = null;
object excludedElements = null;
//string connectionString = "Data Source=http://bi.syncfusion.com/olap/msmdpump.dll; Initial Catalog=Adventure Works DW 2008 SE;";
string connectionString = @"Data Source=SYNCLAPN7420; Initial Catalog=Adventure Works DW;locale identifier=1033;";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string conStringforDB = ""; //Enter appropriate connection string to connect database for saving and loading operation of reports
[System.Web.Http.ActionName("InitializeGrid")]
[System.Web.Http.HttpPost]
public Dictionary<string, object> InitializeOlapGrid(Dictionary<string, object> jsonResult)
{
OlapDataManager DataManager = null;
dynamic customData = serializer.Deserialize<dynamic>(jsonResult["customObject"].ToString());
if (customData is Dictionary<string, object> && customData.ContainsKey("includedElements"))
{
includedElements = customData["includedElements"];
excludedElements = customData["excludedElements"];
}
DataManager = new OlapDataManager(connectionString);
DataManager.SetCurrentReport(CreateOlapReport());
DataManager.OverrideDefaultFormatStrings = true;
return htmlHelper.GetJsonData(jsonResult["action"].ToString(), DataManager, jsonResult.ContainsKey("gridLayout") ? jsonResult["gridLayout"].ToString() : null, Convert.ToBoolean(jsonResult["enablePivotFieldList"].ToString()));
}
[System.Web.Http.ActionName("InitializeChart")]
[System.Web.Http.HttpPost]
public Dictionary<string, object> InitializeChart(Dictionary<string, object> jsonResult)
{
dynamic customData1 = serializer.Deserialize<dynamic>(jsonResult["customObject"].ToString());
if (customData1 is Dictionary<string, object> && customData1.ContainsKey("includedElements"))
{
includedElements = customData1["includedElements"];
excludedElements = customData1["excludedElements"];
}
OlapDataManager DataManager = new OlapDataManager(connectionString);
DataManager.SetCurrentReport(CreateOlapReport());
return pivotChart.GetJsonData(jsonResult["action"].ToString(), DataManager);
}
private OlapReport CreateOlapReport()
{
OlapReport olapReport = new OlapReport();
olapReport.CurrentCubeName = "Adventure Works";
MeasureElements measureElement = new MeasureElements();
measureElement.Elements.Add(new MeasureElement { UniqueName = "[Measures].[Internet Sales Amount]" });
DimensionElement dimensionElementRow = new DimensionElement();
dimensionElementRow.Name = "Date";
dimensionElementRow.AddLevel("Fiscal", "Fiscal Year");
DimensionElement dimensionElementSlicer = new DimensionElement();
dimensionElementSlicer.Name = "Customer";
dimensionElementSlicer.AddLevel("Customer Geography", "Country");
if (includedElements as string != null)
dimensionElementSlicer.Hierarchy.LevelElements["Country"].Add(new MemberElement() { UniqueName = includedElements });
//Spefifying the Excluded row elements
DimensionElement excludedSlicerElement = new DimensionElement();
excludedSlicerElement.Name = "Customer";
excludedSlicerElement.AddLevel("Customer Geography", "Country");
if (excludedElements != null)
{
IEnumerable<object> collection = (IEnumerable<object>)excludedElements;
foreach (object item in collection)
{
excludedSlicerElement.Hierarchy.LevelElements["Country"].Add(new MemberElement() { UniqueName = item.ToString() });
}
}
olapReport.SeriesElements.Add(dimensionElementRow);
olapReport.SlicerElements.Add(dimensionElementSlicer, excludedSlicerElement);
olapReport.CategoricalElements.Add(measureElement);
return olapReport;
}
}
} |