<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    
 <link href="https://cdn.datatables.net/2.0.3/css/dataTables.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.js"></script>   
 <link href="https://cdn.datatables.net/responsive/3.0.0/css/responsive.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/responsive/3.0.0/js/dataTables.responsive.js"></script>
<link href="https://cdn.datatables.net/rowgroup/1.5.0/css/rowGroup.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/rowgroup/1.5.0/js/dataTables.rowGroup.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.2/underscore-min.js" integrity="sha512-anTuWy6G+usqNI0z/BduDtGWMZLGieuJffU89wUU7zwY/JhmDzFrfIZFA3PY7CEX4qxmn3QXRoXysk6NBh5muQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    
    <meta charset=utf-8 />
    <title>DataTables - JS Bin</title>
  </head>
  <body>
    <div class="container">
      <table id="example" class="display nowrap cell-border" width="100%">
        <thead>
          <tr>
            <th class="red">0</th>
            <th class="red">Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
            <th>Age 1</th>
            <th>Age 2</th>
            <th>Age 3 </th>
            <th>Age 4</th>
            <th>Age 5 </th>
            <th>Age 6</th>
            <th class="red">Age 7</th>
            <th class="red">Age 8</th>
            <th class="red">Age 9</th>
            <th class="never">year</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th>0</th>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
            <th>Age 1</th>
            <th>Age 2</th>
            <th>Age 3 </th>
            <th>Age 4</th>
            <th>Age 5 </th>
            <th>Age 6</th>
            <th>Age 7</th>
            <th>Age 8</th>
            <th>Age 9</th>
            <th class="never">year</th>
          </tr>
        </tfoot>
        <tbody>
          <tr>
            <td></td>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$3,120</td>
            <td>61</td>
            <td>61</td>
            <td>61</td>
            <td>61</td>
            <td>61</td>
            <td>61</td>
            <td>61</td>
            <td>61</td>
            <td>61</td>
            <td>2022</td>
          </tr>
          <tr>
            <td></td>
            <td>Garrett Winters</td>
            <td>Director</td>
            <td>Edinburgh</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$5,300</td>
            <td>63</td>
            <td>63</td>
            <td>63</td>
            <td>63</td>
            <td>63</td>
            <td>63</td>
            <td>63</td>
            <td>63</td>
            <td>63</td>
            <td>2022</td>
          </tr>
          <tr>
            <td></td>
            <td>Ashton Cox</td>
            <td>Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2009/01/12</td>
            <td>$4,800</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>2023</td>
          </tr>
           <tr>
            <td></td>
            <td>Ashton Simpsons</td>
            <td>Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2015/01/12</td>
            <td>$4,800</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>66</td>
            <td>2023</td>
          </tr>
          <tr>
            <td></td>
            <td>Cedric Kelly</td>
            <td>Javascript Developer</td>
            <td>Edinburgh</td>
            <td>22</td>
            <td>2012/03/29</td>
            <td>$3,600</td>
            <td>22</td>
            <td>22</td>
            <td>22</td>
            <td>22</td>
            <td>22</td>
            <td>22</td>
            <td>22</td>
            <td>22</td>
            <td>22</td>
            <td>2024</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;
}
.red {background-color: LavenderBlush;}
.right {text-align:right;}
 
var table = new DataTable('#example', {
  columnDefs: [
    { className: 'dtr-control', targets: [0] },
    { orderable: false, targets: [0] },
    { responsivePriority: 1, targets: [0, 1, 13, 14, 15] }
],
  //orderFixed: [16, 'desc'],  // not working
    order: [[16, 'desc']], // order is on col #1 and #6
  responsive: {
    details: {
        type: 'column',
        target: 'tr',
        renderer: function (api, rowIdx, columns) {
          var data = $.map(columns, function (col, i) {
            return col.hidden
            ? '<p class="has-text-grey px-2 py-2"><span class="has-text-weight-semibold smallcaps">'+ col.title + ' : </span>' + col.data + '</p>'
            : '';
            }).join('');
        return data ;
        }
        }
  },
   rowGroup: {
        dataSrc: 16,
          endRender: function (rows, group) {
            var resposniveVisiblity = $('#example').DataTable().columns().responsiveHidden().toArray();
            var numVisible = resposniveVisiblity.filter(x => x === true).length;
         //   var totalCols = $('#example').DataTable().columns().toArray().length;
            //var numInvisible = 17 - numVisible;
            var numInvisible = resposniveVisiblity.filter(x => x === false).length;
            
            // May need to perfom a check to make sure there are at least 4 columns visible otherwise colspan will be a negative number
            var valueColspan = numVisible - 3;
            
            var table = $('#example').DataTable();
            
            var age7Index = table.column( 13 ).index('visible')
            console.log(age7Index)
            return $('<tr/>')
           // .append('<td>Visible columns ' + numVisible + ' - Invisibles col ' + numInvisible + '</td>')
              .append('<td class="right" colspan="' + valueColspan + '">Visible columns ' + numVisible + ' - Invisibles ' + numInvisible + '</td>')
              .append('<td class="red right">7</td>')
              .append('<td class="red right">8</td>')
              .append('<td class="red right">9</td>');
            //  .append('<td>never</td>');
            
          }
    },
    initComplete: function () {
      debounceDraw( this.api() );
    }
});
function debounceDraw(table) {
 
    var drawDebouncedFn = _.debounce(function() {
      console.log('resize')
        table.draw();
    }, 1000);
 
    table.on('responsive-resize', drawDebouncedFn);
}
3 errors 3 warnings
Line 16: Bad line breaking before '?'.
Line 27: 'arrow function syntax (=>)' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
Line 30: 'arrow function syntax (=>)' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).
Line 37: Missing semicolon.
Line 38: Missing semicolon.
Line 59: Missing semicolon.
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers