<!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>
<link href="https://cdn.datatables.net/rowgroup/1.1.3/css/rowGroup.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/rowgroup/1.1.3/js/dataTables.rowGroup.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>tableName</th>
            <th>index</th>
            <th>weight</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>tableName</th>
            <th>index</th>
            <th>weight</th>
          </tr>
        </tfoot>
        <tbody>
          <tr>
            <td>table1</td>
            <td>1</td>
            <td>100</td>
          </tr>
          <tr>
            <td>table1</td>
            <td>1</td>
            <td>100</td>
          </tr>
          <tr>
            <td>table2</td>
            <td>1</td>
            <td>90</td>
          </tr>
          <tr>
            <td>table2</td>
            <td>1</td>
            <td>90</td>
          </tr>
          <tr>
            <td>table2</td>
            <td>1</td>
            <td>90</td>
          </tr>
          <tr>
            <td>table1</td>
            <td>2</td>
            <td>95</td>
          </tr>
          <tr>
            <td>table2</td>
            <td>2</td>
            <td>80</td>
          </tr>
          <tr>
            <td>table2</td>
            <td>2</td>
            <td>80</td>
          </tr>
          <tr>
            <td>table2</td>
            <td>2</td>
            <td>80</td>
          </tr>
          <tr>
            <td>table1</td>
            <td>3</td>
            <td>100</td>
          </tr>
          <tr>
            <td>table1</td>
            <td>3</td>
            <td>200</td>
          </tr>
           <tr>
            <td>table2</td>
            <td>3</td>
            <td>60</td>
          </tr>
          <tr>
            <td>table2</td>
            <td>3</td>
            <td>60</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;
}
 
$(document).ready( function () {
  var table = $('#example').DataTable({
    order: [[1, 'asc']],  // Sort by index column
    columnDefs: [
      {
        targets: 1,
        visible: false  // Hide index column
      }
    ],
    rowGroup: {
      dataSrc: (row)=> {return 'table: ' + row[0]+' index'+row[1]},  // Group by index column
      startRender: function ( rows, group ) {
        return 'Total salary in '+group+' :'+rows.data().pluck(2).reduce((a, b) => a + parseInt(b), 0); // Display after the two rows
      },
    }
  });
} );
1 error 2 warnings
Line 11: 'arrow function syntax (=>)' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
Line 11: Missing semicolon.
Line 13: 'arrow function syntax (=>)' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers