Get the result of filterby and do something with it
purnama Jun 2, 2009 5:43 AMHello,
I hope my question is understandable. I have a Table like this :
Type | Recipient | Amount
A | Max Test | -100
A | Maria MusterFrau | -200
B | Andreas Mustermann | 250
Amount Total : -50
I create the table with rich:dataTable. On every column i have filterBy and sortBy Method. The code is like this:
<h:panelGrid id="aRenderPanel" > <rich:dataTable id="reveneueTable" value="#{revenueReportBean.revenues}" var="revenue" width="500px" columnClasses="center, revenueHeight" rows="8" reRender="ds, aRenderPanel, scrollInfo" onRowMouseOver="this.style.backgroundColor='#F1F1F1'" onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"> <f:facet name="header"> <h:outputText value="Umsätze"/> </f:facet> <rich:column sortBy="#{revenue.transactionDate}" > <f:facet name="header"> <h:outputText value="Datum"/> </f:facet> <h:outputText value="#{revenue.transactionDate}"> <f:convertDateTime pattern="dd.MM.yyyy" timeZone="GMT+2" /> </h:outputText> <a4j:support event="onmouseover" reRender="revenueDetails" actionListener="#{revenueReportBean.processRevenueDetail}"> <a4j:actionparam name="rowid" value="#{revenue.id}" assignTo="#{revenueReportBean.detailEntityId}" /> </a4j:support> </rich:column> <rich:column sortBy="#{revenue.type}" filterBy="#{revenue.type}" filterEvent="onkeyup" > <f:facet name="header"> <h:outputText value="Art" ></h:outputText> </f:facet> <h:outputText value="#{revenue.type}"/> <a4j:support event="onmouseover" reRender="revenueDetails" actionListener="#{revenueReportBean.processRevenueDetail}"> <a4j:actionparam name="rowid" value="#{revenue.id}" assignTo="#{revenueReportBean.detailEntityId}" /> </a4j:support> </rich:column> <rich:column sortBy="#{revenue.recipient}" filterBy="#{revenue.recipient}" filterEvent="onkeyup" > <f:facet name="header"> <h:outputText value="Empfänger"/> </f:facet> <h:outputText value="#{revenue.recipient}"/> <a4j:support event="onmouseover" reRender="revenueDetails" actionListener="#{revenueReportBean.processRevenueDetail}"> <a4j:actionparam name="rowid" value="#{revenue.id}" assignTo="#{revenueReportBean.detailEntityId}" /> </a4j:support> </rich:column> <rich:column sortBy="#{revenue.amount}" align="right" filterBy="#{revenue.amount}" filterEvent="onkeyup" > <f:facet name="header"> <h:outputText value="Betrag"/> </f:facet> <h:outputText value="#{revenue.amount}" > <f:convertNumber type="currency" currencyCode="EUR" maxFractionDigits="2" /> </h:outputText> <a4j:support event="onmouseover" reRender="revenueDetails" actionListener="#{revenueReportBean.processRevenueDetail}"> <a4j:actionparam name="rowid" value="#{revenue.id}" assignTo="#{revenueReportBean.detailEntityId}" /> </a4j:support> </rich:column> <rich:column filterMethod="#{revenueReportBean.filterTags}" > <f:facet name="header"> <h:inputText value="#{revenueReportBean.filterTagsValue}" id="tagFilter"> <f:verbatim>Tags<br/></f:verbatim> <a4j:support event="onkeyup" reRender="reveneueTable, filterAmountTotalText" ignoreDupResponses="true" requestDelay="700" oncomplete="setCaretToEnd(event);" /> </h:inputText> </f:facet> <rich:dropSupport id="dropSupporter" dropValue="bla" value="blub" acceptedTypes="tags" dropListener="#{revenue.processDrop}" reRender="tagsRepeat, reveneueTable" > <rich:dndParam name="revenue" value="#{revenue}" /> </rich:dropSupport> <a4j:repeat id="tagsRepeat" value="#{revenue.tags}" var="tag"> <a4j:commandButton value="#{tag.name}" style="margin-right: 2px; margin-bottom: 2px;" actionListener="#{revenue.removeTag}" reRender="tagsRepeat, reveneueTable" /> </a4j:repeat> </rich:column> <f:facet name="footer"> <rich:datascroller id="ds" reRender="scrollInfo, pageIndexText" renderIfSinglePage="false" pageIndexVar="pageIndex" pagesVar="pages" inactiveStyle="color: grey !important; border-top-color: grey !important;"> </rich:datascroller> </f:facet> </rich:dataTable> <h:outputText id="pageIndexText" value="Seite #{pageIndex} von #{pages} #{pageCount} " rendered="#{pages ge 1}" /> <br /> <h:outputText id="filterAmountTotalText" value="Gesamt Summe: #{revenueReportBean.filterAmountTotal}" > <f:convertNumber type="currency" currencyCode="EUR" maxFractionDigits="2" /> </h:outputText> <br /> </h:panelGrid>
I Want to do something like this:
If the user do the filter (write something in the filter input field) the "Amount Total" should be changed dynamically according to the filter result.
I tried to do it with filterMethod instead of filterBy. And it works. Each object will go through my custom filter method and if the object passed the filter criteria, i will manipulate the "amout total" accordingly.
But if i use filterMethod, i can not use sortBy because the sort event will be in the custom filter input field. thats means, everytime user klick on the filter input field. it will try to sort. user wont have a chance to type anything in the filter input field.
So now im looking for a way which i can sum up the "amount total" of the filter result. and still having the sortby functioning.
thank you
Arthur