0
votes

Im trying to add somehow to datable's column filtering an autocomplete feature. I created Set with LastNames of clients, also created String text field with getter+setter in my Bean as required in example, but don't know how to add it the filter. Could you help me with it!?

in Bean

private Set<String> lastNames = new HashSet<String>(); //for autocomplite
private String text; //for autocomplite

dataTable

<p:dataTable id="table" value="#{clientsListBean.clientList}" var="item" style="width:95%" styleClass="dataTable"
            sortMode="multiple" paginator="true" rows="20"  editable="true" sortOrder="descending" 
            draggableColumns="true" emptyMessage="No clients found with given search criteria"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >


        <p:column headerText="Last Name" filterBy="last_name" sortBy="last_name" style="width:auto; text-align:center" for="autocompl" > 
                <p:autoComplete id="autocompl" value="#{clientsListBean.text}" completeMethod="#{clientsListBean.lastNames}" /> 
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{item.last_name}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{item.last_name}" style="width:100%" />
                    </f:facet>
                </p:cellEditor>
        </p:column>
1

1 Answers

1
votes

You should use this group of code instead of your code.

ManagedBean

public class ClientsListBean implements Serializable{
private Set<String> lastNames = new HashSet<String>();

public ClientsListBean(){
    lastNames.add("john");
    lastNames.add("marry");
    lastNames.add("hudson");
}

/**
 * @return the lastNames
 */
public Set<String> getLastNames() {
    return lastNames;
}

/**
 * @param lastNames the lastNames to set
 */
public void setLastNames(Set<String> lastNames) {
    this.lastNames = lastNames;
}

}

Datatable

<h:form>
        <p:dataTable id="table" value="#{clientsListBean.lastNames}" var="item" style="width:95%" styleClass="dataTable"
                     sortMode="multiple" paginator="true" rows="20"  editable="true" sortOrder="descending" 
                     draggableColumns="true" emptyMessage="No clients found with given search criteria"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >


            <p:column headerText="Last Name" filterBy="#{item}" sortBy="#{item}" style="width:auto; text-align:center" > 
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{item}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{item}" style="width:100%" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
        </p:dataTable>
    </h:form>