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

Pass parameter for know which cube load

Hi, i want pass parameter (string) for know which cube i have to load, 

i was thinking something like:

 @Html.EJ().Olap().OlapClient("OlapClient1").Url("http://192.168.50.141:70//api/OlapClient").Title("Titulos a Pagar").Parameter(stringParameter)

or if have another way for do this, i'll appreciate that

Thanks!

5 Replies

SP Sastha Prathap Selvamoorthy Syncfusion Team October 14, 2016 12:53 PM UTC

Hi Felipe, 
 
You can change the connection string by passing string to an object through the parameter “customObject” to initialize the control. Please find the following sample code snippet that can achieve your requirement. 
 
Here is the code snippet for sending the “customObject” in sample. 
$("#OlapClient").ejOlapClient({ url: "../api/OlapClient", title: "OLAP Browser", displaySettings: { mode: "gridonly" }, customObject: { "cube": "cubeChange" } }); 
 
Here is the code snippet for modified the connectionString using “customObject” in WebAPI controller (Server Side). 
static string connectionString = "Data Source=http://bi.syncfusion.com/olap/msmdpump.dll; Initial Catalog=Adventure Works DW 2008 SE;"; 
 
   ///... 
 
[System.Web.Http.ActionName("InitializeClient")] 
[System.Web.Http.HttpPost] 
public Dictionary<string, object> InitializeClient(Dictionary<string, object> jsonResult) 
{ 
   OlapDataManager DataManager = null; 
   dynamic customData = serializer.Deserialize<dynamic>(jsonResult["customObject"].ToString()); 
   if (customData is Dictionary<string, object> && customData.ContainsKey("report")) 
   { 
     if (customData["cube"] == "cubeChange") 
     { 
         connectionString = // modified your connectionString 
         DataManager = new OlapDataManager(connectionString); 
         DataManager.SetCurrentReport(CreateOlapReport1()); // specify the OlapReport for the modified cube 
     } 
    else 
         DataManager.SetCurrentReport(CreateOlapReport()); 
            }       return olapClientHelper.GetJsonData(jsonResult["action"].ToString(), DataManager, jsonResult["clientParams"].ToString()); 
} 
 
    ///.. 
 
// specify the OlapReport for the modified cube as below example 
 
private OlapReport CreateOlapReport1() 
{ 
    OlapReport olapReport = new OlapReport(); 
    olapReport.Name = "Default Report"; 
    olapReport.CurrentCubeName = "Adventure Works"; 
 
    DimensionElement dimensionElementColumn = new DimensionElement(); 
    //Specifying the Name for the Dimension Element 
    dimensionElementColumn.Name = "Customer"; 
    dimensionElementColumn.AddLevel("Customer Geography", "Country"); 
 
    MeasureElements measureElementColumn = new MeasureElements(); 
    //Specifying the Name for the Measure Element 
    measureElementColumn.Elements.Add(new MeasureElement { Name = "Customer Count" }); 
 
    DimensionElement dimensionElementRow = new DimensionElement(); 
    //Specifying the Dimension Name 
    dimensionElementRow.Name = "Date"; 
    dimensionElementRow.AddLevel("Fiscal", "Fiscal Year"); 
 
    ///Adding Row Members 
    olapReport.SeriesElements.Add(dimensionElementColumn); 
    ///Adding Column Members 
    olapReport.CategoricalElements.Add(dimensionElementRow); 
    ///Adding Measure Element 
    olapReport.CategoricalElements.Add(measureElementColumn); 
    return olapReport; 
} 
 
Regards, 
Sastha Prathap S. 



FA Felipe Alves October 20, 2016 11:53 AM UTC

Hi Sastha,

Can you show me how i do this?

$("#OlapClient").ejOlapClient({ url: "../api/OlapClient", title: "OLAP Browser", displaySettings: { mode: "gridonly" }, customObject: { "cube""cubeChange" } }); 

I understand "Olapclient" it's id from some component, but i want know which is...

If you can show me all code from this part i can finish!

Thanks!


FA Felipe Alves October 20, 2016 01:21 PM UTC

I created at my controller something like


  Dictionary<string, Object > try= new Dictionary<string, Object>();
            

            var s = new {cubeName= "cube", cubeCatalog= "catalog" };
            ewqe.Add("c", s);
            ViewBag.teste = try

But when go to api this viewbag.teste values its empty, just have parameter, but value key its empty


FA Felipe Alves October 20, 2016 04:32 PM UTC

i did here,

Thanks


SP Sastha Prathap Selvamoorthy Syncfusion Team October 21, 2016 06:28 AM UTC

Hi Felipe, 
 
We have prepared a sample where you can change the cube by passing the Cube name through “CustomObject” to server side from sample level itself. Please find the sample code snippet and sample link below for your reference. 
 
Sample Code for passing the CustomObject from sample. 
    @Html.EJ().Olap().OlapClient("PivotClient1").Url(Url.Content("~/api/OlapClient")).Title("OLAP Browser").CustomObject(@ViewBag.test) 
 
Sample Code for passing the CustomObject from controller to Viewpage. 
        public ActionResult Index() 
        { 
            Dictionary<string, object> test = null;//Dictionary datatype 
            test = new Dictionary<string, object>(); 
            test.Add("cube", "Channel Sales"); 
            ViewBag.test = test; 
            return View(); 
        } 
 
 
Regards, 
Sastha Prathap S. 


Loader.
Live Chat Icon For mobile
Up arrow icon