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 - Set the Initial Image

By default, the image that the Gallery widget displays initially is the first item of the data source. To specify another item to be initially displayed, assign its index in the dataSource to the selectedIndex option.

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

As an alternative, you can specify the initial image using its data source object. In this case, assign the object to the selectedItem option.

jQuery
JavaScript
var galleryData = [{
    imageAlt: "Maria",
    imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png"
}, {
    imageAlt: "John",
    imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person2.png"
}, {
    imageAlt: "Xavier",
    imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person3.png"
}];

$(function () {
    $("#galleryContainer").dxGallery({
        dataSource: galleryData,
        height: 300,
        selectedItem: galleryData[1]
    });
});
Angular
HTML
TypeScript
<dx-gallery
    [dataSource]="galleryDataSource"
    [height]="300"
    [selectedItem]="selectedItem">
</dx-gallery>
import { DxGalleryModule } from "devextreme-angular";
// ...
export class AppComponent {
    galleryDataSource = [{
        imageAlt: "Maria",
        imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person1.png"
    }, {
        imageAlt: "John",
        imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person2.png"
    }, {
        imageAlt: "Xavier",
        imageSrc: "https://js.devexpress.com/Content/images/doc/19_1/PhoneJS/person3.png"
    }];
    selectedItem = this.galleryDataSource[1];
}
@NgModule({
    imports: [
        // ...
        DxGalleryModule
    ],
    // ...
})
See Also