DataTables - 在页面加载时打开所有子行 [英] DataTables - Open all Child Rows on Page Load

查看:166
本文介绍了DataTables - 在页面加载时打开所有子行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的表有子行,其中有一个切换来打开第1列中的每一行。(我发现这个函数在线管理子行)如何更改这个以便子行总是打开所以我可以得到摆脱第一列。 https://jsfiddle.net/6k0bshb6/30/

At the moment my table has child rows with a toggle to open each row in column 1. (I found this function online for managing the child rows) how can I change this so that child rows are always open so I can get rid of column one. https://jsfiddle.net/6k0bshb6/30/

// This function is for displaying data from HTML "data-child-value" tag in the Child Row.
function format(value) {
      return '<div>Hidden Value: ' + value + '</div>';
  }

// This function is for handling Child Rows.
    $('#example').on('click', 'td.details-control', function () {
          var tr = $(this).closest('tr');
          var row = dataTable.row(tr);

          if (row.child.isShown()) {
              // This row is already open - close it
              row.child.hide();
              tr.removeClass('shown');
          } else {
              // Open this row
              row.child(format(tr.data('child-value'))).show();
              tr.addClass('shown');
          }
    }); 


推荐答案

使用以下代码显示所有子行:

Use the code below to show all child rows:

$("#example").DataTable().rows().every( function () {
    var tr = $(this.node());
    this.child(format(tr.data('child-value'))).show();
    tr.addClass('shown');
});

参见更新了jsFiddle 代码和演示。

参见 jQuery DataTables:如何展开/折叠所有子行以获取更多示例和信息。

See jQuery DataTables: How to expand/collapse all child rows for more examples and information.

这篇关于DataTables - 在页面加载时打开所有子行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆