【问题标题】:Dynamically add headers in table datatable在表数据表中动态添加表头
【发布时间】:2012-07-31 08:04:44
【问题描述】:

是否可以使用 dataTables 处理 THEAD 中的 2 行?

<table>
    <thead>
        ## row 1
        ## row 2
    </thead>
    <tbody></tbody>
</table> 

在第 1 行中,我需要 2 个单列和一个带有 colspan="3" 的列:

<tr>
    <th></th>
    <th></th>
    <th colspan="3"></th>
</tr>

在第 2 行我需要 5 列:

<tr>
    <th></th>
    <th></th>
    <th></th>
    <th></th>
</tr>

但我有一种情况,我不需要 5 列,而只需要 3 列。

这可以动态生成吗?

更新:我试过了:http://datatables.net/release-datatables/examples/basic_init/complex_header.html

但是没有很好的例子它是如何生成的。

【问题讨论】:

  • 表头中的两行代表什么事实?
  • "但我有一个案例,我不需要 5 列,而只需要 3 列。"你的意思是两行还是第二行 - 你能展示这两种情况的例子吗?

标签: javascript jquery html datatables


【解决方案1】:

如果你看example link you posted的源代码,似乎很清楚:

<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th rowspan="2">Rendering engine</th>
            <th rowspan="2">Browser</th>
            <th colspan="3">Details</th>
        </tr>
        <tr>
            <th>Platform(s)</th>
            <th>Engine version</th>
            <th>CSS grade</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th rowspan="2">Rendering engine</th>
            <th rowspan="2">Browser</th>
            <th>Platform(s)</th>
            <th>Engine version</th>
            <th>CSS grade</th>
        </tr>
        <tr>
            <th colspan="3">Details</th>
        </tr>
    </tfoot>

(从上面的链接中提取的代码)


关于查看源代码的一句话:在Firefox中,您可以按ctrl + u查看页面源代码。即使页面上有大量的 jQuery 操作,该窗口中的源代码也将始终是原始代码,无需 DOM 修改。

【讨论】:

  • 好的,我明白了,已经明白了。可以说我不需要“详细信息”列。我可以更改 .dataTable 函数中的标题吗?通过更改 aoColumns 或函数...?
  • @iam:我不知道。为什么将不需要的数据放入 HTML 中?只需将其忽略并相应地调整 HTML。或者查看fnSetColumnVisdatatables.net/api。我不确定我明白你想要做什么。请说得更清楚。
  • 如果您不想要“详细信息”列,是否可以不将其从 HTML 中删除?基本上在 DataTables 中,您必须有一个单元格来唯一地处理每一列(即您可以单击以对列进行排序等的单元格)。您可以拥有任意数量的 colspan 等,但必须具有引用每一列的能力。
猜你喜欢
  • 1970-01-01
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-12
  • 2015-03-02
  • 2019-05-30
  • 2013-06-10
相关资源
最近更新 更多