0

By default bootstrap table is sorted using the first column. This setting can be changed with data-sort-name="column_name" data-sort-order="asc/desc" as mentioned here link.

In my scenario the column names are created dynamically based on a python script. As such the data-sort-name option is not helpful.

Is it possible to specify the column I want the default sorting to be done by the column index?

  <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>
Tomek
  • 85
  • 1
  • 2
  • 12

1 Answers1

0

I've solved the problem by adding the following script with column index 1:

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