Need a special offer?Find out if your project fits.
+

How to validate pivot table fields changes

Answered
Josh asked on August 25, 2022

Hello,
Can we validate whenever a user changes the fields in a pivot table?
Currently, I tried and it doesn't seem readily available. I can see how to track the fields changes, but not how to validate them.
https://www.flexmonster.com/question/track-pivot-fields-changes/

8 answers

Public
Maksym Diachenko Maksym Diachenko Flexmonster August 26, 2022

Hello, Josh!

Thank you for your question.

The validation of the report can be done based on the reportchange event used for tracking changes.
Firstly, you need to have the variable where the report will be saved every time it is changed. If the validation failed, then you can revert changes done by the user by setting the old report with the setReport API call. Also, you can notify users about the validation process with the alert API call.

Our team prepared the example of fields change validation, where changes in columns are blocked: https://jsfiddle.net/flexmonster/3j9k5z0u/.
Please let us know if this approach works for you.

Best Regards,
Maksym 

Public
Josh August 26, 2022

That's a possibility, but I think it would be even better if the following were to occur:
Within the Fields dialogue, if a user removes all measures, the "Apply" button gets grayed out and disabled. It's not even possible to update the pivot with the current fields selected. The only option is to adjust or cancel.
I think it would be helpful to have a similar feature for dimensions or other values of data. Is there currently a way to do that?

Public
Maksym Diachenko Maksym Diachenko Flexmonster August 29, 2022

Hello, Josh!

Thank you for your feedback.
Yes, it is possible to implement a similar behavior, either by disabling the "Apply" button in the build-in Field List or by creating your own Field List:

Disabling the "Apply" button

Our team prepared a JSFiddle where the "Apply" button gets disabled: https://jsfiddle.net/flexmonster/qvc0wyfd/. In this example, the "Columns" list should contain exactly one field. Otherwise, the "Apply" button is disabled.
In the example, the mouseup event listener is added, as this event can indicate both when the user stops dragging the field or selects it inside the "All Fields" tab. Inside the mouseup listener, querySelector is used for retrieving the "Columns" list. If the validation condition is not satisfied, the fm-ui-disabled class is added to the "Apply" button to disable it.
Kindly note that this example does not cover the case when hierarchies on the grid are dragged. To restrict changes made by dragging, we suggest disabling it by setting the dragging: false in the grid options or using the approach from our previous reply. Also, this approach may not work with future versions of Flexmonster if the CSS rules are changed.

Creating Your Custom Field List

Another possible solution is implementing your own custom Field List. This way, you can add any additional validation logic before applying the changes to the component.
Here you can see an example where a custom Field List was implemented to handle custom validation logic: https://www.flexmonster.com/question/limit-row-column-selection-to-1-field/#answer-36577. Although the "Apply" button is not disabled in that example, you can create your Field List in a way that will cover all your needs.
For more details about creating a custom Field List, please see the following ticket: https://www.flexmonster.com/question/prevent-to-modify-fields-options/#answer-20339.

Hope you will find these solutions helpful. Feel free to contact us if other questions arise. 

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster September 13, 2022

Hello, Josh!

Hope you are doing well.
We wonder if you tried one of the suggested approaches for validating changes in the Field List. 
Our team would like to hear your feedback.

Best Regards,
Maksym

Public
Josh September 13, 2022

Hello,
I was not yet able to. I got side-tracked with higher priority items. When I do eventually try these approaches I'll try to update this ticket with my findings.

Public
Maksym Diachenko Maksym Diachenko Flexmonster September 14, 2022

Hi, Josh!

Thank you for your reply.
Our team would be grateful for your feedback.

Best Regards,
Maksym

Public
Josh September 21, 2022

Hello,
Good and bad news. I was able to test the "Disabling the 'Apply' button" option in my local. It seemed to do exactly what I was aiming for as demonstrated with the jsfiddle example.
The bad news is that I won't get to see it in action because the issue that necessitated it is moot. We won't be implementing it.
Thank you for your help though.

Public
Maksym Diachenko Maksym Diachenko Flexmonster September 22, 2022

Hi, Josh!

Thank you for your feedback.
We are glad to hear that the issue is resolved either way.
As always, feel free to write to us should other questions arise.

Best Regards,
Maksym

Please login or Register to Submit Answer