DataTable - Lazy
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
You need to do the filtering and sorting yourself in lazy mode by connecting to a remote url. In lazy mode, datatable just passes you the state and expect the new data.
We do it something like this:
...where loadItems() and getCount() do server-side queries for the items and the count of items (for pagination).
Code: Select all
<p-dataTable [value]="items" [rows]="rowsPerPage" [paginator]="true" [pageLinks]="9" resizableColumns="true" selectionMode="multiple" [(selection)]="selectedItems" [lazy]="true" [totalRecords]="totalItems" (onLazyLoad)="loadItems($event)" (onFilter)="getCount($event)" class="datalist">
You shall specify an event callback to the onFilter like this:
The $event object holds the following data (extracted from DataTable showcase page):
After that, whenever the totalItems var changes, the dataTable will rerender itself.
Hope this helps you
Code: Select all
(onFilter)="getCount($event)"
Here, the getCount() fires an HTTP request to a remote server that returns the number of items that match the filtering criteria, so you can rebuild your datatable with the appropriate number of pages. The returned (integer) value should be stored in a variable, e.g. this.totalItems, and you should set this to the datatable like:onFilter - event.filters: Filters object having a field as the property key and an object with value, matchMode as the property value.
Callback to invoke when data is filtered.
Code: Select all
[totalRecords]="totalItems"
Hope this helps you
-
- Information
-
Who is online
Users browsing this forum: No registered users and 24 guests