How to save slice and addCalculatedMeasure for user and loaded for custom data source

Answered
Brad Huang asked on March 25, 2021

Because I will save slice and addCalculatedMeasure for user,
[Case 1] I want to load addCalculatedMeasure into fieldsList.
[Case 2] If user has slice, I want to addCalculatedMeasure into slice and run query.

But I failed in both cases.
Case 1: I want to load addCalculatedMeasure into fieldsList.
Step1. init pivot without opening fieldsList
Step2. addCalculatedMeasure
Step3. openFeilds with CalculatedMeasure inside

var pivot = new Flexmonster(report: {dataSource: {type: "api",url: 'myURL'},
slice:null,//no slice
options:{configuratorActive: false}});//Do not open field list
pivot.addCalculatedMeasure({formula: 'OOO', uniqueName: "XXX"});//addCalculatedMeasure
pivot.openFieldsList();//open fields

Case 2: If user has slice, I want to addCalculatedMeasure into slice and run query.
Step1. init pivot without opening fieldsList
Step2. addCalculatedMeasure
Step3. openFeilds with CalculatedMeasure inside

var pivot = new Flexmonster(report: {dataSource: {type: "api",url: 'myURL'},
slice:null,//no slice
options:{configuratorActive: false}});//Do not open field list
pivot.addCalculatedMeasure({formula: 'OOO', uniqueName: "XXX"});//addCalculatedMeasure
pivot.runQuery(mySlice);//load slice and runQuery

5 answers

Public
Milena Pechura Milena Pechura Flexmonster March 29, 2021

Hello, Brad,
 
Thank you for explaining the issues in detail and for providing the examples. This info greatly helped us to understand the cases better.
Please find our comments regarding each point below.
 
1) First of all, we would like to provide further info about the logic of the configuratorActive property:
If the slice is specified, it is possible to configure whether to show the Field List or not. However, in case the slice is not defined in the report, the Field List will be shown by default.
 
Getting to the point, to disable the default opening of the Field List in your case, we suggest specifying an empty report object in the Flexmonster instance. Then, please use the setReport API call with the calculated measure defined in the slice. With this config, the slice is not loaded to the grid, but the calculated measure is shown in the Field List.
Please see the following example for reference: https://jsfiddle.net/flexmonster/yknodjq8/.
 
2) To add the measure in the slice, we suggest modifying the slice object and using the runQuery API call to set the new slice: https://jsfiddle.net/flexmonster/d7Lszxy5/.
 
Please let us know if our response helped.
Do not hesitate to contact us in case any other questions arise.
 
Best regards,
Milena

Public
Milena Pechura Milena Pechura Flexmonster April 9, 2021

Hi, Brad,
 
Hope you are doing well!
 
We were wondering whether our response helped you with your questions.
Could you please let us know if you achieved the desired component behavior?
 
Looking forward to hearing from you.
 
Kind regards,
Milena

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster April 23, 2021

Hi Brad!
 
Just checking in if you've had a chance to read our previous response. Have you found it helpful?
 
We would be happy to hear your feedback.
 
Regards,
Mykhailo

Public
Brad Huang April 27, 2021

After combining your suggestion, this approach works fine for me.

var pivot = new Flexmonster({});
pivot.setReport({
dataSource: {type: "api",url: "my_url"}
slice:getSlice()
});

function getSlice() {
//if no slice return null;
}

 

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster April 27, 2021

Brad,
 
Thank you for your fast response, it is good to hear you've found a solution that suits you!
 
As always, feel free to reach out in case there is anything else we can help you with.
 
Regards,
Mykhailo

Please login or Register to Submit Answer