init上的DataTables子行或嵌套表

时间:2017-04-12 15:21:31

标签: javascript jquery datatables

我想知道是否有办法让所选列出现在this example from DataTables.net中的嵌套/子行中,但没有使用jquery进行手动解析?

有类似的问题,但没有人回答,所以我希望这个问题会得到更多的关注:)

我已尝试responsive这样的选项:

var table = $("#example").DataTable({
        "processing": true,
        "serverSide": true,
        "scrollY":'60vh',
        "scrollCollapse":true,
        //"scrollX":true,
        "responsive":true,
        "ajax": {
            "url":upTableUrl,
            "data":function(d) {
              d.file = $.urlParam('file');//'data_extr.json';
            search_obj = d;
           }
      },      "columns":[
              ...
      ],
      "columnDefs":[
              ...
      ]
    });

和一些html(在这里注意django):

<table width="100%" class="display nowrap table table-striped table-bordered" id="example" cellspacing="0">
        <thead>
            <tr>
              {% for col in columns %}<th>{{col}}</th>
              {% endfor %}
            </tr>
        </thead>
        <tfoot>
          <tr>
            {% for col in columns %}<th>{{col}}</th>
            {% endfor %}
          </tr>
        </tfoot>
      </table>

该表仍然是x轴可滚动的,没有按钮或其他东西出现。

1 个答案:

答案 0 :(得分:1)

使用Row details要求您编写自己的格式化功能。

但是,您可以使用Responsive扩展名,其中列可以在特定条件下显示在子行中。

默认情况下,扩展程序会隐藏所有不适合子行中容器的列,请参阅this example

但是,您可以通过将special classes应用于相应的th元素或使用columns.className选项来控制列的可见性,请参阅this example