DataView

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


import { DataView, DataViewLayoutOptions } from 'primereact/dataview';
         

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


<DataView value={products} listTemplate={listTemplate} />
         

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


<DataView value={products} itemTemplate={listTemplate} paginator rows={5} />
         

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

Sort By Price

<DataView value={products} listTemplate={listTemplate} header={header()} sortField={sortField} sortOrder={sortOrder} />
         

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. As in list layout, the grid layout also requires PrimeFlex Grid classes to define how the grid is displayed per screen sizes.


<DataView value={products} itemTemplate={itemTemplate} layout={layout} header={header()} />
         

While data is being loaded. Skeleton component may be used to indicate the busy state.


<DataView value={products} itemTemplate={itemTemplate} layout={layout} header={header()} />
         

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.