DevExtreme jQuery/JS - Customize Item Appearance

To customize views in the MultiView, define a custom template for them. For Angular, AngularJS, and Knockout apps, DevExtreme provides a markup component called dxTemplate. The following code shows how you can use dxTemplate to define a template for MultiView views.

If you use jQuery alone, combine the HTML markup for items manually with jQuery DOM manipulation methods. To apply this markup, use the itemTemplate callback function as shown in the following code.

JavaScript
  • var multiViewItems = [{
  • title: "Personal Data",
  • data: {
  • firstName: "John",
  • lastName: "Smith",
  • birthYear: 1986
  • }
  • }, {
  • title: "Contacts",
  • data: {
  • phone: "(555)555-5555",
  • email: "John.Smith@example.com"
  • }
  • },
  • // ...
  • ];
  •  
  • $(function() {
  • $("#multiViewContainer").dxMultiView({
  • dataSource: multiViewItems,
  • itemTemplate: function (itemData, itemIndex, itemElement) {
  • var mainContainer = $("<div style='margin:25px;'>");
  • mainContainer.append("<h1>" + itemData.title + "</h1>");
  •  
  • var info = $("<div style='text-align:left;'>");
  • for (var field in itemData.data) {
  • info.append("<p>" + field + ": <b>" + itemData.data[field] + "</b></p>");
  • }
  • mainContainer.append(info);
  • itemElement.append(mainContainer);
  • }
  • });
  • });

You can also customize an individual view. For this purpose, declare a template for this view as a script and pass its id to the template field.

HTML
JavaScript
  • <script id="individualTemplate" type="text/html">
  • <!-- ... -->
  • </script>
  • var multiViewItems = [
  • { text: "Personal Data" },
  • { text: "Contacts", template: $('#individualTemplate') },
  • { text: "Address" }
  • ];

In addition, you can use a 3rd-party template engine to customize widget appearance. For more information, see the 3rd-Party Template Engines article.

See Also