Time for action – loading the DataTable data leisurely
Let us see how to use DataTable with the lazy loading feature.
- Create a DataTable component with the
LazyDataModel
binding and set thelazy
attribute totrue
, as shown in the following code:<p:dataTable id="usersTbl" var="user" value="#{adminController.lazyUserModel}" paginator="true" rows="10" lazy="true"> <p:column headerText="Id" sortBy="#{user.id}" > <h:outputText value="#{user.id}" /> </p:column> <p:column headerText="FirstName" filterBy="#{user.firstName}" sortBy="#{user.firstName}"> <h:outputText value="#{user.firstName}" /> </p:column> </p:dataTable>
- Implement
LazyUserModel
by extendingLazyDataModel
to load data lazily:import org.primefaces.model.LazyDataModel; import org.primefaces.model.SortOrder; public class LazyUserModel...