DevExtreme React - Show and Hide Using the API

NOTE
In this article, the Button widget 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 widget 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.

jQuery
JavaScript
$(function() {
    $("#loadPanelContainer").dxLoadPanel({
        closeOnOutsideClick: true
    });
    $("#buttonContainer").dxButton({
        text: "Show the Load Panel", 
        onClick: function () {
            $("#loadPanelContainer").dxLoadPanel("show");
            // ==== or ====
            $("#loadPanelContainer").dxLoadPanel("toggle", true);
        } 
    });
});
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().LoadPanel()
    .ID("loadPanel")
    .CloseOnOutsideClick(true)
)

@(Html.DevExtreme().Button()
    .ID("button")
    .Text("Show the Load Panel")
    .OnClick(@<text>
        function () {
            $("#loadPanel").dxLoadPanel("show");
            // ==== or ====
            $("#loadPanel").dxLoadPanel("toggle", true);
        } 
    </text>)
)
@(Html.DevExtreme().LoadPanel() _
    .ID("loadPanel") _
    .CloseOnOutsideClick(True)
)

@(Html.DevExtreme().Button() _
    .ID("button") _
    .Text("Show the Load Panel") _
    .OnClick("button_click")
)

<script>
    function button_click() {
        $("#loadPanel").dxLoadPanel("show");
        // ==== or ====
        $("#loadPanel").dxLoadPanel("toggle", true);
    }
</script>

With Angular, AngularJS, or Knockout, use a different technique. Bind the visible property of the LoadPanel widget to a component property (in Angular), a scope property (in AngularJS), or an observable variable (in Knockout). After that, change this property/variable, and the LoadPanel will appear or disappear.

Angular
HTML
TypeScript
<dx-load-panel
    [closeOnOutsideClick]="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
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-load-panel="{
        closeOnOutsideClick: true,
        bindingOptions: {
            visible: 'isLoadPanelVisible'
        }
    }"></div>
    <div dx-button="{
        text: 'Show the Load Panel',
        onClick: showLoadPanel
    }"></div>
</div>
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function DemoController($scope) {
        $scope.isLoadPanelVisible = false;
        $scope.showLoadPanel = function () {
            $scope.isLoadPanelVisible = true;
        }
    });
Knockout
HTML
JavaScript
<div data-bind="dxLoadPanel: {
    closeOnOutsideClick: true,
    visible: isLoadPanelVisible
}"></div>
<div data-bind="dxButton: {
    text: 'Show the Load Panel',
    onClick: function (e) {
        e.model.isLoadPanelVisible(true);
    }
}"></div>
var viewModel = {
    isLoadPanelVisible: ko.observable(false)
};

ko.applyBindings(viewModel);

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 widget, assign it to the corresponding onEventName option. For example, in the following code, a handler of the shown event is assigned to the onShown option. This handler hides the LoadPanel three seconds after it was shown.

jQuery
JavaScript
$(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
HTML
TypeScript
<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
    ],
    // ...
})

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
var shownEventHandler1 = function (e) {
    // First handler of the "shown" event
};

var shownEventHandler2 = function (e) {
    // Second handler of the "shown" event
};

$("#loadPanelContainer").dxLoadPanel("instance")
    .on("shown", shownEventHandler1)
    .on("shown", shownEventHandler2);
See Also