<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.18/rg-1.1.0/datatables.min.css"/>
 
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.18/rg-1.1.0/datatables.min.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 class="bg-inverse">
                                <tr>
                                    <th class="bb-2 bg-inverse text-center">Group Type</th>
                                    <th class="bb-2 bg-inverse text-center">Description</th>
                                    <th class="bb-2 bg-inverse text-center">Cash</th>
                                    <th class="bb-2 bg-inverse text-center">Meezan Bank DHA </th>
                                    <th class="bb-2 bg-inverse text-center">Js Bank</th>
                                    <th class="bb-2 bg-inverse text-center">Habib Bank Limited</th>
                                    <th class="bb-2 bg-inverse text-center">Meezan Bank Muzammil</th>
                                    <th class="bb-2 bg-inverse text-center">Total</th>
                                </tr>
                            </thead>
        <tfoot>
          <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Start date</th>
            <th>Salary</th>
          </tr>
        </tfoot>
      </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 data = [
    {
      "first_name": "Airi",
      "last_name": "Satou",
      "position": "Accountant",
      "office": "Tokyo",
      "start_date": "28th Nov 08",
      "salary": "$162,700"
    },
     {
      "first_name": "Airi",
      "last_name": "Satou",
      "position": "Accountant",
      "office": "Tokyo",
      "start_date": "28th Nov 08",
      "salary": "$162,700"
    },
     {
      "first_name": "Airi",
      "last_name": "Satou",
      "position": "Accountant",
      "office": "Tokyo",
      "start_date": "28th Nov 08",
      "salary": "$162,700"
    },
    {
      "first_name": "Angelica",
      "last_name": "Ramos",
      "position": "Chief Executive Officer (CEO)",
      "office": "London",
      "start_date": "9th Oct 09",
      "salary": "$1,200,000"
    },
     {
      "first_name": "Angelica",
      "last_name": "Ramos",
      "position": "Chief Executive Officer (CEO)",
      "office": "London",
      "start_date": "9th Oct 09",
      "salary": "$1,200,000"
    },
     {
      "first_name": "Angelica",
      "last_name": "Ramos",
      "position": "Chief Executive Officer (CEO)",
      "office": "London",
      "start_date": "9th Oct 09",
      "salary": "$1,200,000"
    },
    {
      "first_name": "Ashton",
      "last_name": "Cox",
      "position": "Junior Technical Author",
      "office": "San Francisco",
      "start_date": "12th Jan 09",
      "salary": "$86,000"
    },
    {
      "first_name": "Bradley",
      "last_name": "Greer",
      "position": "Software Engineer",
      "office": "London",
      "start_date": "13th Oct 12",
      "salary": "$132,000"
    },
    {
      "first_name": "Bradley",
      "last_name": "Greer",
      "position": "Software Engineer",
      "office": "London",
      "start_date": "13th Oct 12",
      "salary": "$132,000"
    },
    {
      "first_name": "Bradley",
      "last_name": "Greer",
      "position": "Software Engineer",
      "office": "London",
      "start_date": "13th Oct 12",
      "salary": "$132,000"
    },
    {
      "first_name": "Bradley",
      "last_name": "Greer",
      "position": "Software Engineer",
      "office": "London",
      "start_date": "13th Oct 12",
      "salary": "$132,000"
    },
    {
      "first_name": "Bradley",
      "last_name": "Greer",
      "position": "Software Engineer",
      "office": "London",
      "start_date": "13th Oct 12",
      "salary": "$132,000"
    },
    {
      "first_name": "Brenden",
      "last_name": "Wagner",
      "position": "Software Engineer",
      "office": "San Francisco",
      "start_date": "7th Jun 11",
      "salary": "$206,850"
    },
    {
      "first_name": "Brenden",
      "last_name": "Wagner",
      "position": "Software Engineer",
      "office": "San Francisco",
      "start_date": "7th Jun 11",
      "salary": "$206,850"
    },
  ];
  var collapsedGroups = {};
    
  var table = $('#example').DataTable({
    
    data: data,
    columns: [
      { "data": null,
        render: function ( data, type, row ) {
            if (type === 'display') {
              return '';
            }
            return row.last_name + ', ' + row.first_name;
        }
      },
      { "data": "position" },
      { "data": "office" },
      { "data": "start_date" },
      { "data": "salary" }
    ],
    rowGroup: {
        dataSrc: function(row) {
          return row.last_name + ', ' + row.first_name;
        },
        startRender: function ( rows, group ) {
            var collapsed = !!collapsedGroups[group];
            rows.nodes().each(function (r) {
                r.style.display = collapsed ? 'none' : '';
            });
            return $('<tr/>')
                .append( '<td colspan="3">'+group+'</td>' )
                .attr('data-name', group)
                .toggleClass('collapsed', collapsed);
            },          
    }
  });
    // Collapse Groups
    $('#example tbody').on('click', 'tr.dtrg-start', function () {
        var name = $(this).data('name');
        collapsedGroups[name] = !collapsedGroups[name];
        table.draw(false);
    });
} );
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers