This script uses a toggle pattern to set the table visibility to the opposite of its current visibility.
No need for IF/ELSE statements
Table_1.setVisible(!Table_1.isVisible());
Code language: JavaScript (javascript)
You could expand this logic to toggle visibility of multiple widgets at the same time
var newState = !Table_1.isVisible();
Table_1.setVisible(newState);
Chart_1.setVisible(newState);
Panel_1.setVisible(newState);
Code language: JavaScript (javascript)
Why do we define the variable: newState
Instead of doing:
Table_1.setVisible(!Table_1.isVisible());
Chart_1.setVisible(!Table_1.isVisible());
We calculate once:
var newState = !Table_1.isVisible();
This ensures:
All widgets use the same visibility state
Easier debugging
No timing inconsistencies
Cleaner logic
