DataTables 在子行中隐藏行(就像响应扩展一样)

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

我将 DataTables 1.10+ 与 Buttons 的列可见性模块 (colvis) 一起使用,并希望将隐藏的列放在可折叠的子行中,就像响应式扩展在 'details' 行中所做的一样。不过我不想要响应度。

是否可以仅使用响应式插件的 'child-row' 功能或基于 window 宽度的 "turn off" 响应式自动列可见性调整?

简而言之:

响应式插件子行:

我的数据表初始化:

  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
    }
  });

谢谢

为此,您可以在 <thead> 中的 <th> 标签上使用属性 喜欢这个

data-priority="1"

所以你一定有这样的东西:

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

数据优先级可以帮助您选择要保留哪些列与 Datatables 的响应式扩展。并将其添加到您的 <table> 标签中:

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

并且不要忘记从数据表中调用 responsive.js 和 css.js ^^

幸运的是,DataTables 1.10 具有该功能。

查看数据表的子行: https://datatables.net/examples/api/row_details.html