mystarrocks
mystarrocks

Reputation: 4088

selectOneMenu filter by various columns and not just the label

Looking at the "Advanced" example here: http://www.primefaces.org/showcase/ui/input/oneMenu.xhtml, I was able to have two columns in each of the options in my oneMenu, but the filtering only happens on the item's label.

What I would like to be able to do is filter by either of the columns (unlike the example, both my columns contain only text, so they are filterable). Is this customization possible?

Adding filter="true" to either of the <p:column>s doesn't seem to have any effect while the utility: filterFunction to write custom filtering rules seems to operate only on the label also!

<p:outputLabel for="advanced" value="Advanced:"  />
<p:selectOneMenu id="advanced" value="#{selectOneMenuView.theme}" converter="themeConverter" panelStyle="width:180px"
                         effect="fade" var="t" style="width:160px" filter="true" filterMatchMode="startsWith">
  <f:selectItems value="#{selectOneMenuView.themes}" var="theme" itemLabel="#{theme.displayName}" itemValue="#{theme}" />
  <p:column style="width:10%">
    <h:outputText styleClass="ui-theme ui-theme-#{t.name}" />
  </p:column>
  <p:column>
    <h:outputText value="#{t.displayName}" />
  </p:column>
</p:selectOneMenu>

Upvotes: 3

Views: 6602

Answers (2)

Neitan Morales
Neitan Morales

Reputation: 1

you can do it, if you write <f:selectItems value="#{estadoParque.vehiculos}" var="v" itemValue="#{v}" itemLabel="#{v.placa} - #{v.marca}"/>

adding the same elements of the columns itemLabel="#{v.placa} - #{v.marca}"

<p:column headerText="Placa">
                            <h:outputText value="#{t.placa}" />
                        </p:column>
                        <p:column headerText="Marca">
                            <h:outputText value="#{t.marca}" />
                        </p:column>

and your filter will be like filterMatchMode="contains"

it works!!

Upvotes: 0

Kukeltje
Kukeltje

Reputation: 12335

No, sorry, this is not possible with the selectOneMenu. You can add a filterFunction, but in that function you can only filter client-side on the label.

As an alternative, you can use the PrimeFaces AutoComplete which can search server side on anything you want and also display custom content.

Upvotes: 2

Related Questions