【问题标题】:How can I add dynamic columns on datatables如何在数据表上添加动态列
【发布时间】:2014-08-11 14:03:49
【问题描述】:

我正在使用jquery datatables 来显示数据。

 <table  class="report-tbl table-bordered" cellspacing="0" width="100%" id="report-tbl">
            <thead>
                <tr>
                    <th></th>
                    <th><span contenteditable="">Side A</span></th>
                    <th><span contenteditable="">Sode B</span></th>
                    <th><span contenteditable="">Side C</span></th>

                </tr>
            </thead>
            <tbody id="rowcontainer">

            </tbody>
        </table>

我想发生的是,当我点击一个按钮时,数据表会添加一个列'Side D'

您对我如何做到这一点有任何想法吗?原因基于我在谷歌看到的。 jQuery data-tables 尚不支持添加/删除动态列。

谢谢,

【问题讨论】:

  • 您是否考虑过从一开始就将其放入并切换显示?
  • 这只是我要添加的示例列。但有可能超过 2 列。

标签: javascript jquery datatables


【解决方案1】:

如果你正在使用任何 jquery 库,那么试试这个

$($("thead").find("tr")[0]).append("<th <span contenteditable="">Side D</span></th>");

【讨论】:

  • 它只将列附加到表上,但不将其添加到数据表上:(
猜你喜欢
  • 2016-07-15
  • 1970-01-01
  • 2022-07-21
  • 2019-05-30
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
  • 2018-06-16
  • 2017-09-09
相关资源
最近更新 更多