<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
    <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display nowrap" width="100%">
        <thead>
          <tr>
            <th>Col1</th>
            <th>Col2</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>System Architect</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Director</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Technical Author</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Javascript Developer</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Financial Controller</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Integration Specialist</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Sales Assistant</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Integration Specialist</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Javascript Developer</td>
          </tr>
          <tr>
            <td>1</td>
            <td>Software Engineer</td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>
 
body {
  font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
  margin: 0;
  padding: 0;
  color: #333;
  background-color: #fff;
}
 
var table = $('#example').DataTable( {
  columns: [    
    {
        data: "Col1",
        //sorting: false,
        //orderable: false,
        //searchable:false,
        //visible:false             
    },          
    {
        data: "Col2",
        //sorting: false,
        //orderable: false,
        //searchable:false
    }
  ],
  initComplete: function () { 
    var api = this.api();       
    var campo1 = api
        .column( 0 )
        .data()
        .filter( function ( value, index ) {
            return value === 0 ? true : false;
        } )
        .count();
        alert(campo1);
        if ( campo1 === 0 ) {
            api.column(0).visible( false );
        }
  }
} );  
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers