【问题标题】:Sort bootstrap table by column specified with index按索引指定的列对引导表进行排序
【发布时间】:2022-01-08 00:41:21
【问题描述】:

默认情况下,引导表使用第一列进行排序。可以使用此处提到的 data-sort-name="column_name" data-sort-order="asc/desc" 更改此设置link

在我的场景中,列名是基于 python 脚本动态创建的。因此,data-sort-name 选项没有帮助。

是否可以指定我希望按列索引进行默认排序的列?

  <table id="table_example"
     class="table table-striped"
     data-toggle="table"
<thead>
  <tr>
    {% for col in column_names %}
    <th>{{col}}</th>
    {% endfor %}
  </tr>
</thead>
<tbody>
{% for row in row_data %}
    <tr>
    {% for col, row_ in zip(column_names, row) %}
    <td>{{row_}}</td>
    {% endfor %}
    </tr>
  {% endfor %}
</tbody>

【问题讨论】:

    标签: javascript html bootstrap-4


    【解决方案1】:

    我通过添加列索引为 1 的以下脚本解决了这个问题:

     <script>
        $(document).ready(function () {
          $('#table_example').DataTable({
          "order": [[ 1, "desc" ]]
          });
        });
      </script>
    

    【讨论】:

      猜你喜欢
      • 2011-03-16
      • 1970-01-01
      • 2016-09-10
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 2011-05-09
      相关资源
      最近更新 更多