DevExtreme jQuery/JS - Customize the Content

Specifying the Content Template

The template implementation depends on the used framework or library. Examples of jQuery, Angular, and ASP.NET MVC are presented below. They show how to create a template consisting of static (text) and dynamic (the Button widget) content.

HTML
  • $(function() {
  • $("#popupContainer").dxPopup({
  • title: "Popup Title",
  • visible: true,
  • contentTemplate: function (contentElement) {
  • contentElement.append(
  • $("<p />").text("Static Content"),
  • $("<div />").attr("id", "buttonContainer").dxButton({
  • text: "Click me",
  • onClick: function (e) {
  • // ...
  • }
  • });
  • )
  • }
  • });
  • });

Switching Templates On the Fly

If you need to render different templates depending on a specific condition, define them inside the Popup container using the DevExtreme dxTemplate markup component. You can switch the templates on the fly by changing the contentTemplate option's value.

HTML
JavaScript
  • <div id="changeTemplateButton"></div>
  • <div id="popupContainer">
  • <div data-options="dxTemplate: { name: 'template1' }">
  • <p>First template</p>
  • </div>
  • <div data-options="dxTemplate: { name: 'template2' }">
  • <p>Second template</p>
  • </div>
  • </div>
  • $(function() {
  • var popup = $("#popupContainer").dxPopup({
  • title: "Popup Title",
  • visible: true,
  • contentTemplate: "template1"
  • }).dxPopup("instance");
  •  
  • $("#changeTemplateButton").dxButton({
  • text: "Change the Template",
  • onClick: function (e) {
  • var currentTemplate = popup.option("contentTemplate");
  • popup.option("contentTemplate", currentTemplate == "template1" ? "template2" : "template1");
  • popup.show();
  • }
  • });
  • });
See Also