chimos
chimos

Reputation: 664

DataTable's hidden rows in a child row (like Responsive extension does)

I am using DataTables 1.10+ with Buttons' column visibility module (colvis) and would like to have the hidden columns in a collapsable child row, the same way Responsive extension does in the 'details' row. I don't want the responsivity though.

Is it possible to use only that 'child-row' functionality of responsive Plugin or to "turn off" responsivity automatic column-visibility adjusments based on window width?

In short:

Responsive plugin child-row: Child-row example

My DataTables init:

  var oTable = $('#table_sd').DataTable({
    'dom': 'Rrilp<"clear">ti<"clear">lp',
    'processing': true,
    'deferRender': true,
    'Paging': true,
    'pagingType': 'input',
    'displayLength': 25,
    'lengthMenu': [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'Alle']],
    'ordering': true,
    'stateSave': false,
    'responsive': false,
    'columnDefs': [
      {
        'targets': [ 1, 2 ],
        'orderable': false,
        'searchable': false
      }
    ],
    'buttons': [
      $.extend( true, {}, buttonCommon, {
          'extend': 'print',
          'text': 'Print',
          'exportOptions': {
          }
      }),
      {
        'extend': 'collection',
        'text': '<i class="icon fa fa-share-square-o"></i><span class="label">Export ...</span>',
        'collectionLayout': 'fixed one-column',
        'buttons': [
          $.extend( true, {}, buttonCommon, {
              'extend': 'copy',
              'text': 'Copy'
          }),
          $.extend( true, {}, buttonCommon, {
              'extend': 'excel',
              'text': 'XLSX (Excel)'
          }),
          $.extend( true, {}, buttonCommon, {
              'extend': 'csv',
              'text': 'CSV (Excel)'
          }),
          $.extend( true, {}, buttonCommon, {
            'extend': 'pdf',
            'text': 'PDF A4',
            'orientation': 'landscape',
            'pageSize': 'A4'
          }),
          $.extend( true, {}, buttonCommon, {
            'extend': 'pdf',
            'text': 'PDF A3',
            'orientation': 'landscape',
            'pageSize': 'A3'
          })
        ]
      },
      {
        'extend': 'colvis',
        'text': 'Show / Hide columns ...',
        'columns': ':gt(5)',
        'collectionLayout': 'fixed three-column',
        'prefixButtons': [
          {
            'extend': 'colvisGroup',
            'text': '<strong>All</strong>',
            'show': ':hidden'
          },
          {
            'extend': 'colvisGroup',
            'text': '<strong>Default minimal</strong>',
            'show': ':lt(7)',
            'hide': ':visible:not(:lt(7))'
          }
        ]
      }
    ],
    'colReorder': {
      'realtime': false,
      'fixedColumnsLeft': 6
    }
  });

Thanks

Upvotes: 10

Views: 4216

Answers (2)

Henz
Henz

Reputation: 121

Luckily for you, DataTables 1.10 has that functionality.

See DataTables' Child Rows: https://datatables.net/examples/api/row_details.html

Upvotes: 1

Antoine Vincent
Antoine Vincent

Reputation: 63

For this you can use attribute on your <th> tag in the <thead> Like this one

data-priority="1"

So you must have something like this :

<thead>
     <th data-priority="1">One Column Name</th>
     <th>Anonther Column Name</th>
     <th>Another Column Name</th>
</thead>

The data-priority can help you choose what columns you want to keep with the responsive extensions of Datatables. And add this to your <table> tag:

class="display nowrap" cellspacing="0" width="100%"

and don't forget to call the responsive.js and css.js from datatable ^^

Upvotes: 0

Related Questions