简体   繁体   English

p:dataTable,延迟加载和全局过滤器

[英]p:dataTable, lazy loading and global filter

I am using lazy loading ,paging and global filter in the dataTable 我在dataTable中使用延迟加载,分页和全局过滤器

In the lazy load function I add 2 function in order to support 2 scenarios: 在延迟加载函数中,我添加了2个函数以支持2种情况:

1) When the user is paging 1)当用户正在寻呼

2) When the user add a value in the global filter and press "Enter" 2)当用户在全局过滤器中添加一个值并按“ Enter”时

Basically what I need to know is what activity was execute in order to decide what function to use. 基本上,我需要知道要执行什么活动才能决定要使用的功能。

dataTable: dataTable:

     <p:dataTable id="osTable"       
                     var="object"
                     value="#{bean.lazyModel}"
                     selection="#{bean.selectedObjectSet}"
                     selectionMode="single"
                     rowKey="#{object.ID}"
                     paginator="true"
                     paginatorPosition="bottom"
                     paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                     rowsPerPageTemplate="5,10,15"
                     rows="10"
                     widgetVar="objectTable">
            <f:facet name="header"> 
                <p:outputPanel style="float: right"> 
                    <h:outputText value="Search all fields:" /> 
                    <p:inputText id="globalFilter" 
                                 onkeypress="if (event.keyCode == 13) {objectSetTable.filter()}"
                                 style="width:150px"/>
                </p:outputPanel> 
            </f:facet>

load function: 加载功能:

  @Override
public List<CfgSe2deMapping> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
    List<Mapping> data = new ArrayList<Mapping>();


    if (// if user press enter ) {
        data.addAll(MappingHelper.getViaFilter(filters.get("globalFilter")));
    } else {
        data.addAll(MappingHelper.getViaOffSet(first + 1, first + pageSize));
    }

I am using primefaces 3.2 我正在使用primefaces 3.2

Thanks 谢谢

you are thinking this the wrong way. 您在想这是错误的方式。 no matter what the user did, you should always do the same: retrieve data (applying filters, if any) and paginate (return pageSize rows starting from first . 无论用户做了什么,您都应该始终做同样的事情:检索数据(应用过滤器,如果有的话)和分页(返回从first开始的pageSize行)。

why aren't you including the 'first' and 'pageSize' parameters when there's a filter? 为什么有过滤器时不包括“ first”和“ pageSize”参数? rows have to be paginated either way. 行必须以任何一种方式分页。 otherwise the user would be able to see only the first page of filtered results. 否则,用户将只能看到过滤结果的第一页。

Also, you have to override getRowCount method, so that your table shows the right number of pages. 另外,您必须重写getRowCount方法,以便表显示正确的页数。

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

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