React LoadPanel - Show and Hide Using the API
jQuery
To show or hide the LoadPanel programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the LoadPanel, respectively.
$(function() { $("#loadPanelContainer").dxLoadPanel({ hideOnOutsideClick: true }); $("#buttonContainer").dxButton({ text: "Show the Load Panel", onClick: function () { $("#loadPanelContainer").dxLoadPanel("show"); // ==== or ==== $("#loadPanelContainer").dxLoadPanel("toggle", true); } }); });
Angular
To show or hide the LoadPanel programmatically, bind the visible property of the LoadPanel UI component to a component property. After that, change this property, and the LoadPanel will appear or disappear.
<dx-load-panel [hideOnOutsideClick]="true" [(visible)]="isLoadPanelVisible"> </dx-load-panel> <dx-button text="Show the Load Panel" (onClick)="isLoadPanelVisible = true"> </dx-button>
import { DxLoadPanelModule, DxButtonModule } from "devextreme-angular"; // ... export class AppComponent { isLoadPanelVisible: boolean = false; } @NgModule({ imports: [ // ... DxLoadPanelModule, DxButtonModule ], // ... })
Vue
To show or hide the LoadPanel programmatically, bind the visible property of the LoadPanel UI component to a component property. After that, change this property, and the LoadPanel will appear or disappear.
<template> <div> <DxLoadPanel :hide-on-outside-click="true" v-model:visible="isLoadPanelVisible" /> <DxButton text="Show the Load Panel" @click="handleClick" /> </div> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxLoadPanel } from 'devextreme-vue/load-panel'; import { DxButton } from 'devextreme-vue/button'; export default { components: { DxLoadPanel, DxButton }, data() { return { isLoadPanelVisible: false } }, methods: { handleClick() { this.isLoadPanelVisible = true; } } } </script>
React
To show or hide the LoadPanel programmatically, bind the visible property of the LoadPanel UI component to a component property. After that, change this property, and the LoadPanel will appear or disappear.
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { LoadPanel } from 'devextreme-react/load-panel'; import { Button } from 'devextreme-react/button'; class App extends React.Component { constructor(props) { super(props); this.state = { isLoadPanelVisible: false }; this.handleClick = this.handleClick.bind(this); this.handleHide = this.handleHide.bind(this); } handleClick() { this.setState({ isLoadPanelVisible: true }); } handleHide() { this.setState({ isLoadPanelVisible: false }); } render() { return ( <div> <LoadPanel hideOnOutsideClick={true} visible={this.state.isLoadPanelVisible} onHidden={this.handleHide} /> <Button text="Show the Load Panel" onClick={this.handleClick} /> </div> ); } } export default App;
To execute certain commands before or after the LoadPanel is shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property. For example, in the following code, a handler of the shown event is assigned to the onShown property. This handler hides the LoadPanel three seconds after it was shown.
jQuery
$(function() { $("#loadPanelContainer").dxLoadPanel({ onShown: function (e) { setTimeout(function () { e.component.hide(); }, 3000); } }); $("#buttonContainer").dxButton({ text: "Show the Load Panel", onClick: function () { $("#loadPanelContainer").dxLoadPanel("show"); } }); });
Angular
<dx-load-panel [(visible)]="isLoadPanelVisible" (onShown)="hideLoadPanel($event)"> </dx-load-panel> <dx-button text="Show the Load Panel" (onClick)="isLoadPanelVisible = true"> </dx-button>
import { DxLoadPanelModule, DxButtonModule } from "devextreme-angular"; // ... export class AppComponent { isLoadPanelVisible: boolean = false; hideLoadPanel (e) { setTimeout(() => { e.component.hide(); }, 3000); } } @NgModule({ imports: [ // ... DxLoadPanelModule, DxButtonModule ], // ... })
Vue
<template> <div> <DxLoadPanel :hide-on-outside-click="true" v-model:visible="isLoadPanelVisible" @shown="hideLoadPanel" /> <DxButton text="Show the Load Panel" @click="handleClick" /> </div> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxLoadPanel } from 'devextreme-vue/load-panel'; import { DxButton } from 'devextreme-vue/button'; export default { components: { DxLoadPanel, DxButton }, data() { return { isLoadPanelVisible: false } }, methods: { handleClick() { this.isLoadPanelVisible = true; }, hideLoadPanel(e) { setTimeout(() => { e.component.hide(); }, 3000); } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { LoadPanel } from 'devextreme-react/load-panel'; import { Button } from 'devextreme-react/button'; class App extends React.Component { constructor(props) { super(props); this.state = { isLoadPanelVisible: false }; this.handleClick = this.handleClick.bind(this); this.hideLoadPanel = this.hideLoadPanel.bind(this); } handleClick() { this.setState({ isLoadPanelVisible: true }); } hideLoadPanel(e) { setTimeout(() => { this.setState({ isLoadPanelVisible: false }); }, 3000); } render() { return ( <div> <LoadPanel hideOnOutsideClick={true} visible={this.state.isLoadPanelVisible} onShown={this.hideLoadPanel} /> <Button text="Show the Load Panel" onClick={this.handleClick} /> </div> ); } } export default App;
jQuery
If you are going to change event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to the events using the on(eventName, eventHandler) method.
const shownEventHandler1 = function (e) { // First handler of the "shown" event }; const shownEventHandler2 = function (e) { // Second handler of the "shown" event }; $("#loadPanelContainer").dxLoadPanel("instance") .on("shown", shownEventHandler1) .on("shown", shownEventHandler2);
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.