DataTable在子行中隐藏的行(如响应式扩展一样)

chi*_*mos 10 javascript visibility datatables

我正在使用DataTables 1.10+和Buttons的列可见性模块(colvis),并且希望在可折叠子行中具有隐藏列,与响应式扩展在"详细信息"行中的行相同.我不想要响应度.

是否可以仅使用响应式插件的"子行"功能,或者根据窗口宽度"关闭"响应度自动列可见性调整?

简而言之:

  • colvis 需要允许用户显示和隐藏列
  • 隐藏的列应该是可折叠的"子行"
  • 该表不应该响应(如果使用响应式扩展)

响应式插件子行: 子行示例

我的DataTables初始化:

  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
    }
  });
Run Code Online (Sandbox Code Playgroud)

谢谢

小智 1

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

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