All docs
V19.1
24.1
The page you are viewing does not exist in version 24.1.
23.2
The page you are viewing does not exist in version 23.2.
23.1
The page you are viewing does not exist in version 23.1.
22.2
The page you are viewing does not exist in version 22.2.
22.1
The page you are viewing does not exist in version 22.1.
21.2
The page you are viewing does not exist in version 21.2.
21.1
The page you are viewing does not exist in version 21.1.
20.2
The page you are viewing does not exist in version 20.2.
20.1
The page you are viewing does not exist in version 20.1.
19.2
19.1
18.2
18.1
17.2
A newer version of this page is available. Switch to the current version.

DevExtreme jQuery - Customize Item Appearance

Gallery items are not sctrictly images. They can contain text or other elements of your choice. For a minor customization of Gallery items, you can use the default item template. This template defines the appearance of an item depending on whether specific fields are present or absent from the item's data object. For example, the following code generates two items: one is disabled and the other has a specified alt attribute.

jQuery
JavaScript
$(function () {
    $("#galleryContainer").dxGallery({
        dataSource: [{
            imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png",
            disabled: true
        }, {
            imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person2.png",
            imageAlt: "Peter"
        }],
        height: 300
    });
});
Angular
HTML
TypeScript
<dx-gallery
    [dataSource]="galleryDataSource"
    [height]="300">
</dx-gallery>
import { DxGalleryModule } from "devextreme-angular";
// ...
export class AppComponent {
    galleryDataSource = [{
        imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png",
        disabled: true
    }, {
        imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person2.png",
        imageAlt: "Peter"
    }];
}
@NgModule({
    imports: [
        // ...
        DxGalleryModule
    ],
    // ...
})

Using the default item template is the easiest way to customize an item, but it lacks flexibility. Instead, you can define a custom template. For Angular, AngularJS and Knockout apps, DevExtreme provides a markup component called dxTemplate. The following code gives a simple example of how you can use dxTemplate to customize gallery items.

Angular
HTML
TypeScript
<dx-gallery
    [dataSource]="galleryDataSource"
    [height]="300"
    itemTemplate="item">
    <div *dxTemplate="let data of 'item'">
        <p><b>Name</b>: <span>{{data.name}}</span></p>
        <img src="{{data.path}}" alt="{{data.name}}" />
    </div>
</dx-gallery>
import { DxGalleryModule } from "devextreme-angular";
// ...
export class AppComponent {
    galleryDataSource = [
        { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png", name: "Maria" },
        { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person2.png", name: "John" },
        { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person3.png", name: "Xavier" }
    ];
}
@NgModule({
    imports: [
        // ...
        DxGalleryModule
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-gallery="{
        dataSource: galleryData,
        height: 300,
        itemTemplate: 'item'
    }" dx-item-alias="item">
        <div data-options="dxTemplate: { name: 'item' }">
            <p><b>Name</b>: <span>{{item.name}}</span></p>
            <img ng-attr-src="{{item.path}}" ng-attr-alt="{{item.name}}" />
        </div>
    </div>
</div>
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function DemoController($scope) {
        $scope.galleryData = [
            { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png", name: "Maria" },
            { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person2.png", name: "John" },
            { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person3.png", name: "Xavier" }
        ];
    });
NOTE
The dx-item-alias directive specifies the variable that is used to access the item object.
Knockout
HTML
JavaScript
<div data-bind="dxGallery: {
    dataSource: galleryData,
    height: 300,
    itemTemplate: 'item'
}">
    <div data-options="dxTemplate: { name: 'item' }">
        <p><b>Name</b>: <span data-bind="text: name"></span></p>
        <img data-bind="attr: { src: path, alt: name }" />
    </div>
</div>
var viewModel = {
    galleryData: [
        { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png", name: "Maria" },
        { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person2.png", name: "John" },
        { path: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person3.png", name: "Xavier" }
    ]
};

ko.applyBindings(viewModel);

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

JavaScript
$(function () {
    $("#galleryContainer").dxGallery({
        dataSource: galleryData,
        height: 300,
        itemTemplate: function(e){
            e.itemElement.empty();
            e.itemElement.append("<p><b>Name</b>: " + e.itemData.name + "</p>");
            e.itemElement.append("<img src=\"" + e.itemData.path + "\" alt=\"" + e.itemData.name + "\"/>");
        }
    });
});

You can also customize an individual Gallery item. For this purpose, declare a template for this item as a script and pass its id to the template field of the item's data object.

HTML
JavaScript
<script id="individualTemplate" type="text/html">
    <!-- ... -->
</script>
var galleryData = [{
    imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png",
    imageAlt: "Maria",
    template: $("#individualTemplate"),
},
    // ...
];

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

View Built-In Template Engine Demo View 3rd-Party Template Engine Demo

See Also