Angular 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.

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, 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.

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
    ],
    // ...
})
Vue
<template>
    <div>
        <DxLoadPanel
            :close-on-outside-click="true"
            :visible.sync="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>
React
import React from 'react';
import 'devextreme/dist/css/dx.common.css';
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
                    closeOnOutsideClick={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
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
    ],
    // ...
})
Vue
<template>
    <div>
        <DxLoadPanel
            :close-on-outside-click="true"
            :visible.sync="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>
React
import React from 'react';
import 'devextreme/dist/css/dx.common.css';
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
                    closeOnOutsideClick={true}
                    visible={this.state.isLoadPanelVisible}
                    onShown={this.hideLoadPanel}
                />
                <Button
                    text="Show the Load Panel"
                    onClick={this.handleClick}
                />
            </div>
        );
    }
}

export default App;

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