DevExtreme jQuery/JS - Show and Hide the Popup

API

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

To show or hide the Popup 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 Popup, respectively.

With Angular, Vue or React, use a different technique. Bind the visible property of the Popup widget to a component property. After that, change this component property, and the Popup will appear or disappear.

  • <template>
  • <div>
  • <DxPopup
  • title="Popup Title"
  • :visible.sync="isPopupVisible">
  • <template>
  • <p>Popup content</p>
  • </template>
  • </DxPopup>
  • <DxButton
  • text="Show the Popup"
  • @click="showPopup"
  • />
  • <DxButton
  • text="Hide the Popup"
  • @click="hidePopup"
  • />
  • </div>
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.common.css';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { DxPopup } from 'devextreme-vue/popup';
  • import { DxButton } from 'devextreme-vue/button';
  •  
  • export default {
  • components: {
  • DxPopup,
  • DxButton
  • },
  • data() {
  • return {
  • isPopupVisible: false
  • }
  • },
  • methods: {
  • showPopup() {
  • this.isPopupVisible = true;
  • },
  • hidePopup() {
  • this.isPopupVisible = false;
  • }
  • }
  • }
  •  
  • </script>

User Interaction

The Popup can also be hidden when a user clicks outside it. To control this behavior of the Popup, use the closeOnOutsideClick option.

  • <template>
  • <DxPopup
  • :visible.sync="isPopupVisible"
  • :close-on-outside-click="true"
  • title="Popup Title"
  • />
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.common.css';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { DxPopup } from 'devextreme-vue/popup';
  •  
  • export default {
  • components: {
  • DxPopup
  • },
  • data() {
  • return {
  • isPopupVisible: true
  • };
  • }
  • }
  • </script>

Events

To execute certain commands before or after the Popup was 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 widget, assign it to the corresponding onEventName option when you configure the widget.

  • <template>
  • <DxPopup ...
  • @showing="onShowing"
  • @shown="onShown"
  • @hiding="onHiding"
  • @hidden="onHidden"
  • />
  • </template>
  •  
  • <script>
  • import 'devextreme/dist/css/dx.common.css';
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import { DxPopup } from 'devextreme-vue/popup';
  •  
  • export default {
  • components: {
  • DxPopup
  • },
  • methods: {
  • onShowing(e) {
  • // Handler of the 'showing' event
  • },
  • onShown(e) {
  • // Handler of the 'shown' event
  • },
  • onHiding(e) {
  • // Handler of the 'hiding' event
  • },
  • onHidden(e) {
  • // Handler of the 'hidden' event
  • }
  • }
  • }
  • </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 hiddenEventHandler1 = function (e) {
  • // First handler of the "hidden" event
  • };
  •  
  • const hiddenEventHandler2 = function (e) {
  • // Second handler of the "hidden" event
  • };
  •  
  • $("#popupContainer").dxPopup("instance")
  • .on("hidden", hiddenEventHandler1)
  • .on("hidden", hiddenEventHandler2);
See Also