Jacob
Jacob

Reputation: 14731

Primefaces datatable lazyloading pagination number of rows are wrongly displayed

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.enter image description here

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?

Upvotes: 0

Views: 4368

Answers (1)

Daniel
Daniel

Reputation: 37051

INMO , you better use LazyDataModel (extend it just like in the showcase - DataTable - Lazy Loading)

Inside your overridden load method you should do the filter logic and have the result , than get its size and use it...

Upvotes: 2

Related Questions