Custom Filtering with Selectonemenu
achittela Oct 15, 2013 3:34 PMI am trying to filter the data table based on the values selected in the selectbox. I have around 10000 records in datatable, to make rendering faster I am using SerializableDataModel and i implemented logic in walk() method and Modify() method.
I am able to filter the data table with the text box values but, i am not able to use the select box filter in this scenario. How can i get column name of the select box and the selected value and it to the filterMap in the modify method ?
I tried filter expression but, it's not working in this scenario.
Walk() method:
@Override public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) throws IOException { // This is method we have to populate a data for DataTable // Range parameter provides the firstRow value and no. of rows value this.firstRow = ((SequenceRange) range).getFirstRow(); this.numberOfRows = ((SequenceRange) range).getRows(); List<CustomerList> cList = getCustomerList(this.firstRow, this.numberOfRows.intValue(), this.sortField, this.ascending); System.out.println("customerList in walk method:" + cList.size()); this.totalRows = new Integer(displayCustomerListOne.size()); System.out.println("displayCustomerListOne.size" + this.totalRows); wrappedKeys = new ArrayList<Integer>(); if (!cList.isEmpty()) { for (CustomerList item : cList) { System.out.println("item.getAvIdPk()" + item.getAvIdPk()); wrappedKeys.add(item.getAvIdPk()); wrappedData.put(item.getAvIdPk(), item); // Once data populated to wrappedKeys and wrappedData call the // process method using visitor parameter visitor.process(context, item.getAvIdPk(), argument); } } }
Modify() method:
@Override public void modify(List<FilterField> filterFields, List<SortField2> sortFields) { filterMap.clear(); String expressionStr = null; ExtendedFilterField extendedFilterField = null; String value = null; Expression filterExpression = null; if (null != sortFields && !sortFields.isEmpty()) { SortField2 sortField2 = sortFields.get(0); Expression sortExpression = sortField2.getExpression(); String expressionString = sortExpression.getExpressionString(); if (!sortExpression.isLiteralText()) { expressionString = expressionString.replaceAll( "[#|$]{1}\\{.*?\\.", "").replaceAll("\\}", ""); } this.sortField = expressionString; if (sortField2.getOrdering() == Ordering.ASCENDING) { this.ascending = true; } else if (sortField2.getOrdering() == Ordering.DESCENDING) { this.ascending = false; } } if (filterFields != null && !filterFields.isEmpty()) { for (FilterField filterField : filterFields) { if (filterField instanceof ExtendedFilterField) { extendedFilterField = (ExtendedFilterField) filterField; value = extendedFilterField.getFilterValue(); if (value != null && !value.equals("")) { filterExpression = extendedFilterField.getExpression(); System.out.println("filterExpression "+filterExpression); expressionStr = filterExpression.getExpressionString(); if (!filterExpression.isLiteralText()) { expressionStr = expressionStr.replaceAll( "[#|$]{1}\\{.*?\\.", "").replaceAll("\\}", ""); } filterMap.put(expressionStr, value); } } } } }
Below is my JSP code:
<rich:dataTable value="#{item}" var="dataTableItem" rowClasses="oddRow,evenRow" footerClass="thclass" id="data" onRowClick="dataTable.onRowSubmit(this);" first="#{item.rowIndex}" rows="20" reRender="pg" sortMode="single"> <rich:column sortable="false" id="col_1"> <f:facet name="header"> <h:panelGroup> <h:outputText /> <br /> <h:outputText /> </h:panelGroup> </f:facet> <h:commandButton style="display: none;" action="#{item.customerDetail}"> <f:param name="selectedAvId" value="#{dataTableItem.avId}" /> </h:commandButton> <h:graphicImage value="images/icoEdit15.gif" style="border:none" alt="Edit"></h:graphicImage> </rich:column> <rich:column sortable="true" headerClass="standardTable_Header" sortBy="#{dataTableItem.changeTypeStatus}" id="col_2"> <f:facet name="header"> <h:panelGroup> <h:outputText value="#{msgs.changeTypeStatus} " id="cl2" /><br> <h:selectOneMenu value="#{item.filterChangeType}"> <f:selectItem itemValue=""/> <f:selectItem itemValue="Enroll"/> <f:selectItem itemValue="De-Enroll"/> <f:selectItem itemValue="Management Company"/> <f:selectItem itemValue="Parent Company"/> <f:selectItem itemValue="Name"/> <f:selectItem itemValue="Owner"/> <f:selectItem itemValue="Brand"/> <f:selectItem itemValue="Comment"/> <f:selectItem itemValue="Address"/> <f:selectItem itemValue="Marketing Rights"/> <a4j:support event="onchange" reRender="data , pg" requestDelay="500" ajaxSingle="true" ignoreDupResponses="true"/> </h:selectOneMenu> </h:panelGroup> </f:facet> <h:outputText id="cl_2" value="#{dataTableItem.changeTypeStatus}" /> </rich:column> <rich:column sortable="true" filterBy="#{dataTableItem.brandMandated}" filterEvent="onkeyup" filterValue="#{item.filterValue4}" sortBy="#{dataTableItem.brandMandated}" id="col_4"> <f:facet name="header"> <h:outputText value="#{msgs.brandmandated}" id="cl4" /> </f:facet> <h:outputText style="white-space:nowrap;" value="#{dataTableItem.brandMandated}" id="cl_4" /> </rich:column> <rich:column sortable="true" sortBy="#{dataTableItem.city}" filterBy="#{dataTableItem.city}" filterEvent="onkeyup" filterValue="#{item.filterValue11}" id="col_11"> <f:facet name="header"> <h:outputText value="#{msgs.city}" id="cl11" /> </f:facet> <h:outputText value="#{dataTableItem.city}" id="cl_11" /> </rich:column> <rich:column sortable="true" sortBy="#{dataTableItem.state}" filterBy="#{dataTableItem.state}" filterEvent="onkeyup" filterValue="#{item.filterValue12}" id="col_12"> <f:facet name="header"> <h:outputText value="#{msgs.state}" id="cl12" /> </f:facet> <h:outputText value="#{dataTableItem.state}" id="cl_12" /> </rich:column> <rich:datascroller id="pg" renderIfSinglePage="false" maxPages="5" for="data" /> </rich:dataTable>