DataView

DataView displays data in grid or list layout with pagination and sorting features.


import { DataViewModule } from 'primeng/dataview';

DataView requires a value to display along with a list template that receives an object in the collection to return content.

Bamboo Watch
Bamboo Watch
AccessoriesINSTOCK
$65
Black Watch
Black Watch
AccessoriesINSTOCK
$72
Blue Band
Blue Band
FitnessLOWSTOCK
$79
Blue T-Shirt
Blue T-Shirt
ClothingINSTOCK
$29
Bracelet
Bracelet
AccessoriesINSTOCK
$15


<p-dataView #dv [value]="products">
    <ng-template pTemplate="list" let-products>
        <div class="grid grid-nogutter">
            <div class="col-12" *ngFor="let item of products; let first = first">
                <div class="flex flex-column xl:flex-row xl:align-items-start p-4 gap-4" [ngClass]="{ 'border-top-1 surface-border': !first }">
                    <img class="w-9 sm:w-16rem xl:w-10rem shadow-2 block xl:block mx-auto border-round" [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + item.image" [alt]="item.name" />
                    <div class="flex flex-column sm:flex-row justify-content-between align-items-center xl:align-items-start flex-1 gap-4">
                        <div class="flex flex-column align-items-center sm:align-items-start gap-3">
                            <div class="text-2xl font-bold text-900">{{ item.name }}</div>
                            <p-rating [(ngModel)]="item.rating" [readonly]="true" [cancel]="false"></p-rating>
                            <div class="flex align-items-center gap-3">
                                <span class="flex align-items-center gap-2">
                                    <i class="pi pi-tag"></i>
                                    <span class="font-semibold">{{ item.category }}</span>
                                </span>
                                <p-tag [value]="item.inventoryStatus" [severity]="getSeverity(item)"></p-tag>
                            </div>
                        </div>
                        <div class="flex sm:flex-column align-items-center sm:align-items-end gap-3 sm:gap-2">
                            <span class="text-2xl font-semibold">{{ '$' + item.price }}</span>
                            <button pButton icon="pi pi-shopping-cart" class="md:align-self-end mb-2 p-button-rounded" [disabled]="item.inventoryStatus === 'OUTOFSTOCK'"></button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </ng-template>
</p-dataView>

Pagination is enabled with the paginator and rows properties. Refer to the Paginator for more information about customizing the paginator.

Bamboo Watch
Bamboo Watch
AccessoriesINSTOCK
$65
Black Watch
Black Watch
AccessoriesINSTOCK
$72
Blue Band
Blue Band
FitnessLOWSTOCK
$79
Blue T-Shirt
Blue T-Shirt
ClothingINSTOCK
$29
Bracelet
Bracelet
AccessoriesINSTOCK
$15


<p-dataView #dv [value]="products" [rows]="5" [paginator]="true">
    <ng-template let-products pTemplate="list">
        <div class="grid grid-nogutter">
            <div class="col-12" *ngFor="let item of products; let first = first">
                <div class="flex flex-column xl:flex-row xl:align-items-start p-4 gap-4" [ngClass]="{ 'border-top-1 surface-border': !first }">
                    <img class="w-9 sm:w-16rem xl:w-10rem shadow-2 block xl:block mx-auto border-round" [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + item.image" [alt]="item.name" />
                    <div class="flex flex-column sm:flex-row justify-content-between align-items-center xl:align-items-start flex-1 gap-4">
                        <div class="flex flex-column align-items-center sm:align-items-start gap-3">
                            <div class="text-2xl font-bold text-900">{{ item.name }}</div>
                            <p-rating [(ngModel)]="item.rating" [readonly]="true" [cancel]="false"></p-rating>
                            <div class="flex align-items-center gap-3">
                                <span class="flex align-items-center gap-2">
                                    <i class="pi pi-tag"></i>
                                    <span class="font-semibold">{{ item.category }}</span>
                                </span>
                                <p-tag [value]="item.inventoryStatus" [severity]="getSeverity(item)"></p-tag>
                            </div>
                        </div>
                        <div class="flex sm:flex-column align-items-center sm:align-items-end gap-3 sm:gap-2">
                            <span class="text-2xl font-semibold">{{ '$' + item.price }}</span>
                            <button pButton icon="pi pi-shopping-cart" class="md:align-self-end mb-2 p-button-rounded" [disabled]="item.inventoryStatus === 'OUTOFSTOCK'"></button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </ng-template>
</p-dataView>

Built-in sorting is controlled by bindings sortField and sortOrder properties from a custom UI.

Bamboo Watch
Bamboo Watch
AccessoriesINSTOCK
$65
Black Watch
Black Watch
AccessoriesINSTOCK
$72
Blue Band
Blue Band
FitnessLOWSTOCK
$79
Blue T-Shirt
Blue T-Shirt
ClothingINSTOCK
$29
Bracelet
Bracelet
AccessoriesINSTOCK
$15

<p-dataView #dv [value]="products" [sortField]="sortField" [sortOrder]="sortOrder">
    <ng-template pTemplate="header">
        <div class="flex flex-column md:flex-row md:justify-content-between">
            <p-dropdown [options]="sortOptions" [(ngModel)]="sortKey" placeholder="Sort By Price" (onChange)="onSortChange($event)" styleClass="mb-2 md:mb-0"></p-dropdown>
        </div>
    </ng-template>
    <ng-template let-products pTemplate="list">
        <div class="grid grid-nogutter">
            <div class="col-12" *ngFor="let item of products; let first = first">
                <div class="flex flex-column xl:flex-row xl:align-items-start p-4 gap-4" [ngClass]="{ 'border-top-1 surface-border': !first }">
                    <img class="w-9 sm:w-16rem xl:w-10rem shadow-2 block xl:block mx-auto border-round" [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + item.image" [alt]="item.name" />
                    <div class="flex flex-column sm:flex-row justify-content-between align-items-center xl:align-items-start flex-1 gap-4">
                        <div class="flex flex-column align-items-center sm:align-items-start gap-3">
                            <div class="text-2xl font-bold text-900">{{ item.name }}</div>
                            <p-rating [(ngModel)]="item.rating" [readonly]="true" [cancel]="false"></p-rating>
                            <div class="flex align-items-center gap-3">
                                <span class="flex align-items-center gap-2">
                                    <i class="pi pi-tag"></i>
                                    <span class="font-semibold">{{ item.category }}</span>
                                </span>
                                <p-tag [value]="item.inventoryStatus" [severity]="getSeverity(item)"></p-tag>
                            </div>
                        </div>
                        <div class="flex sm:flex-column align-items-center sm:align-items-end gap-3 sm:gap-2">
                            <span class="text-2xl font-semibold">{{ '$' + item.price }}</span>
                            <button pButton icon="pi pi-shopping-cart" class="md:align-self-end mb-2 p-button-rounded" [disabled]="item.inventoryStatus === 'OUTOFSTOCK'"></button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </ng-template>
</p-dataView>

DataView supports list and grid display modes defined with the layout property. The helper DataViewLayoutOptions component can be used to switch between the modes however this component is optional and you may use your own UI to switch modes as well.

Bamboo Watch
Bamboo Watch
AccessoriesINSTOCK
$65
Black Watch
Black Watch
AccessoriesINSTOCK
$72
Blue Band
Blue Band
FitnessLOWSTOCK
$79
Blue T-Shirt
Blue T-Shirt
ClothingINSTOCK
$29
Bracelet
Bracelet
AccessoriesINSTOCK
$15
Brown Purse
Brown Purse
AccessoriesOUTOFSTOCK
$120
Chakra Bracelet
Chakra Bracelet
AccessoriesLOWSTOCK
$32
Galaxy Earrings
Galaxy Earrings
AccessoriesINSTOCK
$34
Game Controller
Game Controller
ElectronicsLOWSTOCK
$99
Gaming Set
Gaming Set
ElectronicsINSTOCK
$299
Gold Phone Case
Gold Phone Case
AccessoriesOUTOFSTOCK
$24
Green Earbuds
Green Earbuds
ElectronicsINSTOCK
$89

<p-dataView #dv [value]="products" [layout]="layout">
    <ng-template pTemplate="header">
        <div class="flex justify-content-end">
            <p-dataViewLayoutOptions [layout]="layout"></p-dataViewLayoutOptions>
        </div>
    </ng-template>
    <ng-template let-product pTemplate="list" let-products>
        <div class="grid grid-nogutter">
            <div class="col-12" *ngFor="let product of products; let first = first">
                <div class="flex flex-column xl:flex-row xl:align-items-start p-4 gap-4" [ngClass]="{ 'border-top-1 surface-border': !first }">
                    <img class="w-9 sm:w-16rem xl:w-10rem shadow-2 block xl:block mx-auto border-round" [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image" [alt]="product.name" />
                    <div class="flex flex-column sm:flex-row justify-content-between align-items-center xl:align-items-start flex-1 gap-4">
                        <div class="flex flex-column align-items-center sm:align-items-start gap-3">
                            <div class="text-2xl font-bold text-900">{{ product.name }}</div>
                            <p-rating [ngModel]="product.rating" [readonly]="true" [cancel]="false"></p-rating>
                            <div class="flex align-items-center gap-3">
                                <span class="flex align-items-center gap-2">
                                    <i class="pi pi-tag"></i>
                                    <span class="font-semibold">{{ product.category }}</span>
                                </span>
                                <p-tag [value]="product.inventoryStatus" [severity]="getSeverity(product)"></p-tag>
                            </div>
                        </div>
                        <div class="flex sm:flex-column align-items-center sm:align-items-end gap-3 sm:gap-2">
                            <span class="text-2xl font-semibold">{{ '$' + product.price }}</span>
                            <button pButton icon="pi pi-shopping-cart" class="md:align-self-end mb-2 p-button-rounded" [disabled]="product.inventoryStatus === 'OUTOFSTOCK'"></button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </ng-template>
    <ng-template let-product pTemplate="grid" let-products>
        <div class="grid grid-nogutter">
            <div class="col-12 sm:col-6 lg:col-12 xl:col-4 p-2" *ngFor="let product of products">
                <div class="p-4 border-1 surface-border surface-card border-round">
                    <div class="flex flex-wrap align-items-center justify-content-between gap-2">
                        <span class="flex align-items-center gap-2">
                            <i class="pi pi-tag"></i>
                            <span class="font-semibold">{{ product.category }}</span>
                        </span>
                        <p-tag [value]="product.inventoryStatus" [severity]="getSeverity(product)"></p-tag>
                    </div>
                    <div class="flex flex-column align-items-center gap-3 py-5">
                        <img class="w-9 shadow-2 border-round" [src]="'https://primefaces.org/cdn/primeng/images/demo/product/' + product.image" [alt]="product.name" />
                        <div class="text-2xl font-bold">{{ product.name }}</div>
                        <p-rating [ngModel]="product.rating" [readonly]="true" [cancel]="false"></p-rating>
                    </div>
                    <div class="flex align-items-center justify-content-between">
                        <span class="text-2xl font-semibold">{{ '$' + product.price }}</span>
                        <button pButton icon="pi pi-shopping-cart" class="p-button-rounded" [disabled]="product.inventoryStatus === 'OUTOFSTOCK'"></button>
                    </div>
                </div>
            </div>
        </div>
    </ng-template>
</p-dataView>

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-dataviewContainer element.
p-dataview-listContainer element in list layout.
p-dataview-gridContainer element in grid layout.
p-dataview-headerHeader section.
p-dataview-footerFooter section.
p-dataview-contentContainer of items.
p-dataview-emptymessageEmpty message element.

Screen Reader

The container element that wraps the layout options buttons has a group role whereas each button element uses button role and aria-pressed is updated depending on selection state. Values to describe the buttons are derived from the aria.listView and aria.gridView properties of the locale API respectively.

Refer to paginator accessibility documentation for the paginator of the component.

Keyboard Support

KeyFunction
tabMoves focus to the buttons.
spaceToggles the checked state of a button.