title: How to collapse a primesfaces datatable with a button or a command button?
body: <p>I want to show or hide a primefaces datatables by clicking on their command button, I have a java bean and I can call the java function dashboardView.displayOrHide(). I don't know how to make this happen.</p>
  
  <p>I want to show or hide the datatable, maybe collapse it or not by clicking a button, and save the state of the datatable in the java bean</p>
  
  <p>My version of Primefaces is 6.0.15. </p>
  
  <p>My JSF/xhtml code :</p>
  
  <pre><code>&lt;p:commandButton value="Show Or Hide" id="ajax" action="#{dashboardView.displayOrHide}" style="margin-right:20px;" styleClass="ui-priority-primary" /&gt;
  
  &lt;p:dataTable id="item_#{synopticLocationBean.id}" var="synopticIdBean" value="#{synopticLocationBean.synopticIdBeans}"&gt;
     &lt;p:column headerText="Famille"&gt;
         &lt;h:outputText value="#{synopticIdBean.family}" /&gt;
     &lt;/p:column&gt;
  
     &lt;p:column headerText="BT"&gt;
        &lt;h:outputText value="#{synopticIdBean.brNumber}"/&gt;
     &lt;/p:column&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>My Java code, but I don't know what to do here :</p>
  
  <pre><code>public void buttonAction() {
     System.out.println("test ash retor ana");
  }
  </code></pre>
  
  <p>For the moment I use a javascript function with a button</p>
  
  <p> </p>
  
  <p>And hide or show my datatable with the displayTabInformation js function :</p>
  
  <pre><code>function displayTabInformation(id,dataTableId){
  
      var divDisplay = dataTableId.style.display;
  
      if(divDisplay === ''){
          dataTableId.style.setProperty('display', 'none');
      }else if(divDisplay === 'none'){
          dataTableId.style.setProperty('display', 'block');
      }else{
          if(divDisplay === 'visible'){
              dataTableId.style.setProperty('display', 'none');
          }else{
              if(divDisplay === 'block'){
                  dataTableId.style.setProperty('display', 'none');
              }
          }
      }
  }
  </code></pre>
  
  <p>I would like to make the same function with the java bean for saving which database is show or hide.</p>