I am using lazy loading ,paging and global filter in the dataTable
In the lazy load function I add 2 function in order to support 2 scenarios:
1) When the user is paging
2) When the user add a value in the global filter and press “Enter”
Basically what I need to know is what activity was execute in order to decide what function to use.
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
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
pageSizerows starting fromfirst.why aren’t you including the ‘first’ and ‘pageSize’ parameters when there’s a filter? 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.