Vue LoadPanel - Show and Hide Using the API

NOTE
In this article, the Button UI component is used to demonstrate how to show and hide the LoadPanel. This choice is made for purely demonstrational purposes, and you can do the same operations using another UI component following the same guidelines.

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.

With Angular, Vue, or React, use a different technique. 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
  • :close-on-outside-click="true"
  • v-model:visible="isLoadPanelVisible"
  • />
  • <DxButton
  • text="Show the Load Panel"
  • @click="handleClick"
  • />
  • </div>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.common.css';
  • 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>

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.

  • <template>
  • <div>
  • <DxLoadPanel
  • :close-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.common.css';
  • 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>

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. This approach is more typical of jQuery.

JavaScript
  • 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