【问题标题】:Adding a class to dynamic Bootstrap Table rows将类添加到动态引导表行
【发布时间】:2017-08-04 06:35:06
【问题描述】:

所以我想在我的表格行中添加一个类,除了标题,但我不知道该怎么做。有人知道我该怎么做吗?

这是我的桌子:

<table id="table" class="hidden table table-bordered table-striped table-hover">
    <thead>
        <tr>
            <th data-field="variant">Variant</th>
            <th data-field="description">Description</th>
        </tr>
    </thead>
</table>

这是我目前添加数据并希望将类添加到行的位置

$('#table').bootstrapTable({
    data: returnValue
});

【问题讨论】:

  • 你用的是bootstrapTable插件,你不觉得这些信息对解决有用吗?

标签: javascript jquery html twitter-bootstrap bootstrap-4


【解决方案1】:

查看引导表文档并使用行样式属性, 我不熟悉那个插件,但我猜它应该是这样的

$('#table').bootstrapTable({
    data: returnValue, 
    rowStyle :  function(row, index) {
     return {
     classes: 'text-nowrap another-class',
     css: {"color": "blue", "font-size": "50px"}
     };
 }
});

在此处阅读文档http://bootstrap-table.wenzhixin.net.cn/documentation/

【讨论】:

    【解决方案2】:

    第一个:在html中添加tbody标签table

    第二个:简单的为你添加类tbody tr就这样

    $('#table tbody tr').addClass("newclass");
    

    HTML:

    <table id="table" class="hidden table table-bordered table-striped table-hover">
        <thead>
            <tr>
                <th data-field="variant">Variant</th>
                <th data-field="description">Description</th>
            </tr>
        </thead>
        <tbody>  //tbody added here  
            <tr>
            ....
            </tr>
        </tbody>
    </table>
    

    在 jquery 中

    $('#table tbody tr').addClass("newclass");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      相关资源
      最近更新 更多