JavaScript/jQuery LoadPanel - Show and Hide Using the API
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.
- $(function() {
- $("#loadPanelContainer").dxLoadPanel({
- onShown: function (e) {
- setTimeout(function () {
- e.component.hide();
- }, 3000);
- }
- });
- $("#buttonContainer").dxButton({
- text: "Show the Load Panel",
- onClick: function () {
- $("#loadPanelContainer").dxLoadPanel("show");
- }
- });
- });
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.
- 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);