i have made primefaces data table, can filtered (see below). works fine, have attempted create ability filter start , end date, selecting dates via calendar (it should find dates between 2 dates; notice start date/end date , filter dates button @ top). need filter start , end date filters else.
it invoked via custom method, doesn't return correct values, , importantly if select page on paginator defaults unfiltered list. of disaster. i'd make user can filter start/end date part of whole filtering system. right start/end date fields part of header.
i thought maybe if filter dates fields modify list (bean property) used pull data table (tablefiltered), ensure data pulled limited correct dates have been filtered. didn't work that. don't understand.
inside home.xhtml
<p:outputpanel id="tablecontainer"> <p:remotecommand name="filterbydate" action="#{homecontroller.filterbydate()}" update="tablecontainer" /> <p:datatable var="hbel" id="hbellist" value="#{homecontroller.tablefiltered}" rows="10" paginator="true" paginatortemplate="{currentpagereport} {firstpagelink} {previouspagelink} {pagelinks} {nextpagelink} {lastpagelink} {rowsperpagedropdown}" rowsperpagetemplate="10,100,1000" widgetvar="widgettable" tablestyle="width:auto"> <f:facet name="header"> <p:outputpanel> <p:calendar id="calstartdate" value="#{homecontroller.startdate}" maxdate="#{homecontroller.enddate}" navigator="true" pattern="dd-mmm-yy" placeholder=" start date"> <p:ajax process="calstartdate" partialsubmit="true" event="change"/> </p:calendar> <p:calendar id="calenddate" value="#{homecontroller.enddate}" maxdate="#{homecontroller.enddate}" navigator="true" pattern="dd-mmm-yy" placeholder=" end date"> <p:ajax process="calenddate" partialsubmit="true" event="change"/> </p:calendar> <p:commandbutton id="btnfilter" value="filter dates" ajax="true"> <p:ajax oncomplete="filterbydate()" /> </p:commandbutton> </p:outputpanel> </f:facet> <p:column filterstyle="width: 48px;" filterby="#{hbel.batchid}" headertext="batchid" filtermatchmode="exact"> <h:outputtext value="#{hbel.batchid}" /> </p:column> <p:column filterstyle="width: 48px;" filterby="#{hbel.recordid}" headertext="recordid" filtermatchmode="exact"> <h:outputtext value="#{hbel.recordid}" /> </p:column> <p:column filterby="#{hbel.unitname}" headertext="unitname" filtermatchmode="in"> <f:facet name="filter"> <p:selectcheckboxmenu label="unit" onchange="pf('widgettable').filter()" panelstyle="width:125px" scrollheight="150"> <f:selectitem itemlabel="location" itemvalue="location"/> <f:selectitem itemlabel="unit" itemvalue="unit" /> <f:selectitem itemlabel="customer" itemvalue="direct_customer" /> <f:selectitem itemlabel="occupancy" itemvalue="occupancy" /> <f:selectitem itemlabel="bank account" itemvalue="bank_account" /> </p:selectcheckboxmenu> </f:facet> <h:outputtext value="#{hbel.unitname}" /> </p:column> <p:column filterby="#{hbel.logdate}" headertext="logdate" filtermatchmode="exact"> <h:outputtext value="#{hbel.logdate}" /> </p:column> <p:column filterby="#{hbel.logflag}" headertext="logflag" filtermatchmode="in"> <f:facet name="filter"> <p:selectcheckboxmenu label="flag" onchange="pf('widgettable').filter()" panelstyle="width:125px" scrollheight="150"> <f:selectitem itemlabel="business" itemvalue="b"/> <f:selectitem itemlabel="reconciliation" itemvalue="r" /> <f:selectitem itemlabel="technical" itemvalue="t" /> <f:selectitem itemlabel="warning" itemvalue="w" /> </p:selectcheckboxmenu> </f:facet> <h:outputtext value="#{hbel.logflag}" /> </p:column> <p:column filterby="#{hbel.logfields}" headertext="logfields" filtermatchmode="contains"> <h:outputtext value="#{hbel.logfields}" /> </p:column> <p:column filterby="#{hbel.logreason}" headertext="logreason" filtermatchmode="contains"> <h:outputtext value="#{hbel.logreason}" /> </p:column> </p:datatable> </p:outputpanel>
inside homecontroller.java bean (request scoped)
// custom filtering public void filterbydate() { if (startdate != null && enddate != null) { // new dates (add start , end date range) calendar c = calendar.getinstance(); c.settime(startdate); c.add(calendar.date, -1); date startdatemod = c.gettime(); c.settime(enddate); c.add(calendar.date, 1); date enddatemod = c.gettime(); // reset table first tablefiltered.clear(); // add legal items tablefull (hubtobauexceptionlog hbel : tablefull) { if (hbel != null && hbel.getlogdate().after(startdatemod) && hbel.getlogdate().before(enddatemod)) { tablefiltered.add(hbel); } } } }
from primefaces docs:
filtering
ajax based filtering enabled setting filterby @ column level , providing list keep filtered sublist. suggested use scope longer request viewscope keep filteredvalue filtered list still accessible after filtering.
<p:datatable var="car" value="#{carbean.cars}" filteredvalue="#{carbean.filteredcars}"> <p:column filterby="#{car.model}" headertext="model"> <h:outputtext value="#{car.model}" /> </p:column> ...more columns </p:datatable>
so try add datatable list filteredvalue, keep tablefull value , in filterbydate method populate filtered list.
<p:datatable var="hbel" id="hbellist" value="#{homecontroller.tablefull}" rows="10" filteredvalue="#{homecontroller.tablefiltered}" paginator="true" paginatortemplate="{currentpagereport} {firstpagelink} {previouspagelink} {pagelinks} {nextpagelink} {lastpagelink} {rowsperpagedropdown}" rowsperpagetemplate="10,100,1000" widgetvar="widgettable" tablestyle="width:auto">
Comments
Post a Comment