1

Problem

When creating a dataTable using Bootfaces, I can bring all items of my DB but I need to bring just the ones which field equals a specific number. ¿How can I do that?

Example

Evento (Id, nombre, categoria)

  • Id Nombre Categoria
  • 1 aaaa 1
  • 2 bbbb 2
  • 3 cccc 2

dataTable only brings the first one, Id 1.

Code

<b:dataTable value="#{eventoController.items}" var="item" styleClass="list" scroll-x="true">

    <h:column>
        <f:facet name="header">
            <h:outputText value="#{bundle.ListEventoTitle_idEvento}"/>
        </f:facet>
        <h:outputText value="#{item.idEvento}"/>
    </h:column>
                    
    <h:column>
        <f:facet name="header">
            <h:outputText value="#{bundle.ListEventoTitle_nombre}"/>
        </f:facet>
        <h:outputText value="#{item.nombre}"/>
    </h:column>

    <h:column>
        <f:facet name="header">
            <h:outputText value="#{bundle.ListEventoTitle_idCategoria}"/>
        </f:facet>
        <h:outputText value="#{item.idCategoria}"/>
    </h:column>
                    
</b:dataTable>
  
Community
  • 1
  • 1
  • show your bean code – cjslv Jun 13 '17 at 08:36
  • @Valentina: your last sentence confuses me. Do you want to limit the data table to `ID=1`, or does this already happen, and you want to get rid of the filter? Judging from the context, I suppose you're referring to the first option. – Stephan Rauh Jun 15 '17 at 13:39

1 Answers1

1

Replace the <h:column> by it's BootsFaces counterpart <b:dataTableColumn />. Now you can set the attribute search-value. Most likely you also need to activate multi-column-search='true'and s searching='true'. In your case, that's

<b:dataTable value="#{eventoController.items}" 
             var="item" 
             styleClass="list" 
             scroll-x="true"
             multi-column-search="true"
             searching="true">
    <b:dataTableColumn search-value="1" searchable="true">
       <f:facet name="header">
          <h:outputText value="#{bundle.ListEventoTitle_idEvento}"/>
       </f:facet>
       <h:outputText value="#{item.idEvento}"/>
    </b:dataTableColumn>
    ...
</b:dataTable>

Please keep in mind that the BootsFaces dataTable is a client-side widget. This means that the entire HTML table is sent to the client. That, in turn, makes for fast filtering, pagination, and sorting once the data has been loaded, but if you've got a huge amount of data, you'll want to filter the data on the server side, too.

Also see https://showcase.bootsfaces.net/forms/DataTable.jsf (search for "initial search filter").

Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37