I am trying to implement lazyloading for Primefaces datatable. I have a filter condition which I have implemented as
public List<Request> getRequest(int startingAt, int maxPerPage,
String sortField, SortOrder sortOrder, Map<String,
String> filters) {
Criteria criteria = sessionFactory.getCurrentSession().
createCriteria(Request.class);
for (Map.Entry<String, String> entry : filters.entrySet()) {
if(entry.getValue()!=null){
criteria.add(Restrictions.ilike("prNo",
"%"+entry.getValue()+"%"));
}
}
criteria.setMaxResults(maxPerPage);
criteria.setFirstResult(startingAt);
return criteria.list();
}
and in jsf page
<p:column id="prNo" filterBy="#{req.prNo}"
headerText="PR No">
<h:outputText value="#{req.prNo}" />
</p:column>
The issue I am facing is when filtered rows displays n datatable pagination numbers doesn't change at all, it shows as of the actual number of records. E.g. If filter matches a condition and number of rows for filter condition is 12, then pagination should display as 1 of 3 and pages should be like 1 2 3. See the attached screen shot.
Lazymodel rowCount is set as
lazyModel.setRowCount(getRequestService().getRequestCount());
it's implementation
int count = ((Long) sessionFactory.getCurrentSession()
.createQuery("select count(*) from Request").uniqueResult())
.intValue();
How could I achieve this?
setRowCount
will be set with a size of the filtered data something likelazyModel.setRowCount(criteria.list().size());
– Danielcriteria.list().size()
in managedbean? And is it a good idea of not using DataModel for LazyLoading and overide load method directly in managedbean? – JacobLazyDataModel
(extend it just like in the showcase) , inside your overriddenload
method you should do the filter logic and have the result , than get its size and use it... – Daniel