Despite the COVID-19 outbreak, our team continues operating at full speed. We are always here to support and answer all your questions.

Feel free to reach out by filling this quick form.

Fill the form
Get Free Trial

Disable the editing of a calculated field

Answered
Brendan Fry asked on April 8, 2020

Hi,
We want to create calculated fields that will be visible in the data area but the calculation or the editor should not be visible for that field. 
Essentially disabling this field. We are thinking of prefixing columns with ‘~#’ to do this and then controlled by our user roles.
Images attached for better explanation. Could you tell how this could be possible please?
Thanks
Brendan

6 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 8, 2020

Hello, Brendan,
 
Thank you for contacting us.
 
Controls dedicated to change the calculated values can be hidden using the following approach:
First of all, names and the captions of all calculated values which are required to be not editable have to contain the symbols mentioned by you: “~#”.
 
In order to hide controls from the context menu that appears after the cell is clicked with a right-click, use the following function, allowing to customize the context menu:

pivot.customizeContextMenu(function(items, data, viewType) {
if (data.measure && data.measure.formula && data.measure.uniqueName.includes("~#"))
items.splice(3, 1);
return items;
});

It scans each element of the menu and delete the one dedicated to editing in case the clicked value is the calculated one, and its name contains appropriate symbols.
 
Controls can be removed from the Field List, using the following code snippet:

pivot.on("fieldslistopen", () => {
setTimeout(() => {
let measuresList = document.querySelector("#fm-lst-measures").childNodes;
for (let measure of measuresList)
if (measure.childNodes[0].innerText.includes("~#"))
measure.removeChild(measure.childNodes[1]);
}, 0);
});

It uses the fieldslistopen event which is triggered after the Field List is opened and delete appropriate nodes dedicated to editing of the calculated value.
 
Please check out an example we have prepared for you.
 
Our team would like to kindly draw your attention to the fact that an example demonstrates the general approach of handling such a situation. It does not cover all use cases, e.g., it may work incorrectly for flat form.
 
More information about the customizeContextMenu API in our documentation.
Also, here is a page dedicated to the fieldslistopen event.
 
We hope it works for you.
Do not hesitate to contact us in case of additional questions.
 
Best regards,
Illia

Public
Brendan Fry April 9, 2020

Hi,
Thank for the reply.
The customizeContextMenu works as expected so that’s great.
However, for the code provided for fieldslistopen this works in the values list (red in screenshot) as expected the icon is removed but in the screenshot attached the blue circles I can’t get a handle to in this event as they don’t exist until Calculated Values is expanded. Any suggestions?
Thanks
Brendan

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 9, 2020

Hello, Brendan,
 
Thank you for your feedback.
 
We would like to kindly notice that the provided solution is quite general. In order to remove other UI controls, additional logic may be required.
 
Concerning the blue icon from your screenshot, you are right about the fact that such elements are created dynamically. Thus, custom logic is required in order to track their creation and handle the removal of an appropriate icon.
 
We recommend considering the usage of the MutationObserver, which is a built-in JavaScript object that observes a DOM element and fires a callback in case of changes.
It allows tracking child nodes as well. Therefore, it is possible to trigger the function responsible for removing an appropriate icon as soon as new objects are created.
We recommend checking out the following page in order to get more information about the object and ways to use it.
 
Please let us know if the above solution works for you. In case it does not, our team can consider adding a property that allows making the value read-only in one of the future minor releases.
 
We are looking forward to hearing from you.
 
Best regards,
Illia

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 22, 2020

Hello, Brendan,
 
Our team would like to kindly take an interest in whether you did manage to implement the required functionality.
 
We are looking forward to hearing from you.
 
Best regards,
Illia

Public
Brendan Fry April 23, 2020

Hi,
Thanks for checking back. Unfortunately I haven’t had time to get back to this since I got your response. It seems simple enough though for when I get there.
Will let you know when I find the time.
Thanks
Brendan

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster May 7, 2020

Hello, Brendan,

Our team is wondering if you succeeded to implement the disabling of editing calculated values.

Do not hesitate to write to us in case assistance is needed.

Best regards,
Illia

Please login or Register to Submit Answer