DataTables - rows().data()

by Muhammad Mushtaq Sheikh

HTML

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.7/css/jquery.dataTables.css">
<script src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
            <th></th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
             <th></th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
         <td><input type="checkbox" class='chck'/></td>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
         <td><input type="checkbox" class='chck'/></td>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
        <tr>
         <td><input type="checkbox" class='chck'/></td>
            <td>Ashton Cox</td>
            <td>Junior Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2009/01/12</td>
            <td>$86,000</td>
        </tr>
        <tr>
         <td><input type="checkbox" class='chck'/></td>
            <td>Bradley Greer</td>
            <td>Software Engineer</td>
            <td>London</td>
            <td>41</td>
            <td>2012/10/13</td>
            <td>$132,000</td>
        </tr>
        <tr>
         <td><input type="checkbox" class='chck'/></td>
            <td>Dai Rios</td>
            
            <td>Personnel Lead</td>
           ...

JavaScript

var table;
$(document).ready(function (){
    table = $('#example').DataTable();
    
    
});

 function fun (){
  var data = table
        .rows('.chck:checked')
        .data();
     
    console.log( 'The table has ' + data.length + ' records' );
    console.log( 'Data', data );   
 }