1
votes

I'm trying to do a filter in a datatable (primefaces 3.5). The filter should only be fired when the user clicks on a commandLink.

<h:commandLink title="#{open}"
onclick="$('#form\\:filteredTable\\:statusColumn_filter').val('OPEN'), filteredTable.filter()">
<h:graphicImage name="16x16.png" styleClass="ico" />
</h:commandLink>

My table:

<h:form id="form">
    <h:panelGroup>
        <div>
            <p:dataTable widgetVar="filteredTable" var="y" value="#{x}" rendered="#{w.showFilterButtons}" filteredValue="#{w.filteredX}">
                <p:column id="statusColumn" headerText="label"
                    filterBy="#{y.status}" filterMatchMode="exact"
                    filterStyle="display:none;"
                    filterOptions="#{w.statuses}"> 
                    <h:outputText value="#{y.status.name}"/>
                </p:column>
            </p:dataTable>
        </div>
    </h:panelGroup>
</h:form>

I have 3 problems with this code:

1 - The filter does not work. If I click on the commandLink, the pages reloads but nothing was filtered. Probabily because #form\:filteredTable\:statusColumn_filter').val() returns undefined. So I guess I'm not setting the value to do the filter (right?)

2 - I want to do a default filter, so when the datatable loads the first time it would be already filtered by a status.

3 - This datatable is inside a pop up in google maps. But when I click on the commandLink, the whole page reloads, so the pop up is "closed", the map goes back to the initial zoom. This way, the user will have to zoom again, click on the marker in the map to open the pop up again to see the filtered data. This is not good. There is a way to only reload the datatable?

1

1 Answers

1
votes

I figured it out and forgot to post here my solution.

Server side: the value "x" is the list of the default values. And when the user clicks on the commandButton, a method is called to update the list.

commandButton:

<p:commandButton actionListener="#{bean.upadteXList}" 
    update="filteredTableId"
    oncomplete="filteredTable.filter()"
/>

datatable:

<h:form id="form">
    <h:panelGroup>
        <div>
            <p:dataTable id="filteredTableId" widgetVar="filteredTable" var="y" value="#{x}" rendered="#{w.showFilterButtons}">
                <p:column id="statusColumn" headerText="label"> 
                    <h:outputText value="#{y.status.name}"/>
                </p:column>
            </p:dataTable>
        </div>
    </h:panelGroup>
</h:form>