DevExtreme Angular - Show and Hide Using the API
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
$(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
@(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
<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
<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
<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
$(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
<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.
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
If you have technical questions, please create a support ticket in the DevExpress Support Center.