<!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>
    <script src="https://nightly.datatables.net/rowgroup/js/dataTables.rowGroup.js?_=bc3763029fa6dfaf4c947ef25f079107"></script>
<link href="https://cdn.datatables.net/responsive/2.2.9/css/responsive.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.js"></script>
    
    <meta charset=utf-8 />
    <title>DataTables - Multi-level Collapse / Expand</title>
  </head>
  <body>
    <div class="container">
      <table id="table_orders" class="display compact cell-border" style="width:100%"></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;
}
table.dataTable tr.dtrg-group.dtrg-level-0 td {
    font-weight: bold;
}
table.dataTable tr.dtrg-group td {
    background-color: #e0e0e0;
}
table.dataTable tr.dtrg-group.dtrg-level-1 td:first-child{
    padding-left: 2em;
}
table.dataTable tr.dtrg-group.dtrg-level-1 td{
    background-color: #f0f0f0;
    padding-top: 0.25em;
    padding-bottom: 0.25em;
}
table.dataTable tr.dtrg-group.dtrg-level-2 td:first-child {
    padding-left: 3em;
}
table.dataTable tr.dtrg-group.dtrg-level-2 td {
    background-color: #fff0f0;
}
table.dataTable.compact tbody tr td.order_id {
    padding-left: 4em;
}
 
var data = [{"webmaster":"Tiger Nixon","offer_name":"Power Bank Solar","arcdate":"2020-06-19","order_id":1358639},{"webmaster":"Tiger Nixon","offer_name":"GERBER Bear Grylls","arcdate":"2020-06-19","order_id":1358587},{"webmaster":"Tiger Nixon","offer_name":"GERBER Bear Grylls","arcdate":"2020-06-19","order_id":1358765},{"webmaster":"Tiger Nixon","offer_name":"GERBER Bear Grylls","arcdate":"2020-06-20","order_id":1358910},{"webmaster":"Tiger Nixon","offer_name":"GERBER Bear Grylls","arcdate":"2020-06-20","order_id":1358911},{"webmaster":"Tiger Nixon","offer_name":"GERBER Bear Grylls","arcdate":"2020-06-20","order_id":1359035},{"webmaster":"Tiger Nixon","offer_name":"GERBER Bear Grylls","arcdate":"2020-06-20","order_id":1359131},{"webmaster":"Tiger Nixon","offer_name":"GERBER Bear Grylls","arcdate":"2020-06-20","order_id":1359194},{"webmaster":"Tiger Nixon","offer_name":"Туристический гамак","arcdate":"2020-06-19","order_id":1358762},{"webmaster":"Sonya Frost","offer_name":"A-Plus 4","arcdate":"2020-06-19","order_id":1358666},{"webmaster":"Sonya Frost","offer_name":"Royal Queen","arcdate":"2020-06-19","order_id":1358589},{"webmaster":"Sonya Frost","offer_name":"Royal Queen","arcdate":"2020-06-19","order_id":1358622},{"webmaster":"Sonya Frost","offer_name":"Royal Queen","arcdate":"2020-06-19","order_id":1358708},{"webmaster":"Sonya Frost","offer_name":"Royal Queen","arcdate":"2020-06-19","order_id":1358713},{"webmaster":"Sonya Frost","offer_name":"Royal Queen","arcdate":"2020-06-19","order_id":1358797}];
$(document).ready(function() {
    var collapsedGroups = {};
    var top = '';
    var parent = '';
    var table = $('#table_orders').DataTable({
        data: data,
        responsive: {
            details: {
                display: $.fn.dataTable.Responsive.display.childRowImmediate,
                type: 'none',
                target: ''
            }
        },
      columns: [
            {data: 'webmaster', title:'webmaster'},
            {data: 'offer_name', title: 'offer_name'},
            {data: 'arcdate', title: 'arcdate'},
            {data: 'order_id', title: 'User / Offer / Date / Order', class: 'order_id'},
        ],      
        order: [[0, 'asc'], [1, 'asc'], [2, 'asc']],
        columnDefs: [ {
            targets: [ 0],
            visible: false
        } ],    
        stripeClasses: [],
        paging: false,
        searching: false,
        rowGroup: {
            dataSrc: ['webmaster', 'offer_name', 'arcdate'],
            startRender: function(rows, group, level) {
                var all;
                if (level === 0) {
                    top = group;
                    all = group;
                } else {
                    // if parent collapsed, nothing to do
                    if (!!collapsedGroups[top]) {
                        return;
                    }
                    all = top + group;
                }
                var collapsed = !!collapsedGroups[all];
                rows.nodes().each(function(r) {
                    r.style.display = collapsed ? 'none' : '';
                });
      
                // Add category name to the <tr>. NOTE: Hardcoded colspan
                return $('<tr/>')
                    .append('<td colspan="8">' + group + ' (' + rows.count() + ')</td>')
                    .attr('data-name', all)
                    .toggleClass('collapsed', collapsed);
            }
        }
    });
    table.on('draw', function () {
      table.rows({page: 'current'}).every( function ( rowIdx, tableLoop, rowLoop ) {
        var data = this.data();
        
        // Check to see if any of the rowGroup.dataSrc collapsable rows are collapsed
        if (collapsedGroups[data.webmaster] || collapsedGroups[data.webmaster + data.arcdate]) {
          this.child.hide();
        } else {
          this.child.show();
        }
      } );
    })
    $('#table_orders 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