Toggle Display
Show or hide cards, charts, statistics and tabs at runtime with setDisplay() in ESP-DASH Pro.
ESP-DASH Pro feature. This functionality is available only in the commercial edition of ESP-DASH.setDisplay() shows or hides a widget on the dashboard without removing it. Use it to adapt the dashboard to the current state of your application, for example to reveal configuration cards only in a maintenance mode.
All widgets are displayed by default.
Methods
setDisplay() and displayed() are defined on dash::Component, so they are available on every card, chart, statistic and tab.
setDisplay
bool setDisplay(bool display);Pass true to show the widget and false to hide it. Returns false if the widget is already in the requested state; otherwise marks the display state as changed and returns true. The change is sent to clients on the next call to dashboard.sendUpdates().
displayed
bool displayed() const;Returns true if the widget is currently displayed.
Usage
Hide a widget
card.setDisplay(false); // Card
chart.setDisplay(false); // Chart
stat.setDisplay(false); // Statistic
tab.setDisplay(false); // TabShow a widget
card.setDisplay(true); // Card
chart.setDisplay(true); // Chart
stat.setDisplay(true); // Statistic
tab.setDisplay(true); // TabExample
// ...
dash::ToggleButtonCard maintenance(dashboard, "Maintenance Mode");
dash::SliderCard<int> threshold(dashboard, "Alarm Threshold", 0, 100);
void setup() {
// ...
// Hide the threshold slider until maintenance mode is enabled
threshold.setDisplay(false);
maintenance.onChange([](bool state) {
maintenance.setValue(state);
threshold.setDisplay(state);
dashboard.sendUpdates();
});
}