I have a Primefaces datatable where one column has a Filter drop down menu. I want to set a default value for the filter on page load. By using filterValue
and setting a default value for the option in the backing bean, the value is selected in the menu on page load however the datatable itself isn't actually filtered.
I have tried adding javascript to force the default filter on page load using the below example however it isn't working.
setting default value in primefaces datatable Filter
I have not worked with javascript much so my issue may be there.
JSF Page:
<h:body>
<h:form>
<ui:define name="header" >
<h:outputScript name="common.js" target="body" />
</ui:define>
</h:form>
<p:dataTable var="dataItem" value="#{homepageBean.accounts}"
filteredValue="#{homepageBean.filterAccounts}" widgetVar="dataTableWidgetVar" >
<p:column headerText="Status" id="statusCol" filterBy="status"
filterOptions="#{homepageBean.menu.statusOption}"
filterValue="#{homepageBean.defaultStatus}" >
<h:outputText value="#{dataItem.status}" />
</p:column>
</p:dataTable>
</h:body
common.js page:
function setDefaultFilter() {
dataTableWidgetVar.filter();
}
homepageBean has applicable getters and setters. I am using Primefaces 4.0.