title: Using Javascript to set default filter in primefaces datatable
body: <p>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 <code>filterValue</code> 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.</p>
  
  <p>I have tried adding javascript to force the default filter on page load using the below example however it isn't working.</p>
  
  <p><a href="https://stackoverflow.com/questions/15450274/setting-default-value-in-primefaces-datatable-filter">setting default value in primefaces datatable Filter</a></p>
  
  <p>I have not worked with javascript much so my issue may be there.</p>
  
  <p>JSF Page:</p>
  
  <pre><code>&lt;h:body&gt;
      &lt;h:form&gt;
          &lt;ui:define name="header" &gt;
              &lt;h:outputScript name="common.js" target="body" /&gt;
          &lt;/ui:define&gt;
      &lt;/h:form&gt;
  
  
  &lt;p:dataTable var="dataItem" value="#{homepageBean.accounts}" 
           filteredValue="#{homepageBean.filterAccounts}" widgetVar="dataTableWidgetVar" &gt;
  
          &lt;p:column headerText="Status" id="statusCol" filterBy="status" 
                  filterOptions="#{homepageBean.menu.statusOption}" 
                  filterValue="#{homepageBean.defaultStatus}" &gt;                                   
              &lt;h:outputText value="#{dataItem.status}" /&gt;
          &lt;/p:column&gt;             
  
  &lt;/p:dataTable&gt;      
  
  &lt;/h:body
  </code></pre>
  
  <p>common.js page:</p>
  
  <pre><code>function setDefaultFilter() {
      dataTableWidgetVar.filter();   
  }
  </code></pre>
  
  <p>homepageBean has applicable getters and setters. I am using Primefaces 4.0.</p>