简体   繁体   English

Primefaces数据表延迟加载分页行数被错误地显示

[英]Primefaces datatable lazyloading pagination number of rows are wrongly displayed

I am trying to implement lazyloading for Primefaces datatable. 我正在尝试为Primefaces数据表实现延迟加载。 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 并在jsf页面

<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. 我面临的问题是当过滤的行显示n个数据表分页编号根本没有变化时,它显示实际的记录数。 Eg 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 . 例如,如果过滤器匹配条件,并且过滤条件的行数为12,则分页应显示为1的3 ,页面应为1 2 3 See the attached screen shot. 请参阅随附的屏幕截图。 在此输入图像描述

Lazymodel rowCount is set as Lazymodel rowCount设置为

lazyModel.setRowCount(getRequestService().getRequestCount());

it's implementation 它的实施

int count = ((Long) sessionFactory.getCurrentSession()
                .createQuery("select count(*) from Request").uniqueResult())
                .intValue();

How could I achieve this? 我怎么能实现这个目标?

INMO , you better use LazyDataModel ( extend it just like in the showcase - DataTable - Lazy Loading ) INMO,你最好使用LazyDataModel扩展它就像在展示中一样 - 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... 在重写的加载方法中,您应该执行过滤器逻辑并获得结果,而不是获取其大小并使用它...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM