Search code examples
javascriptjquerytwitter-bootstraptwitter-bootstrap-3bootstrap-table

Table-multiple-sort in boostrap-table doesn't work for multiple tables in one page


I use bootstrap-table and extension table-multiple-sort. When I have two tables in one page (in my case second table is in modal window), in second table I don't have any choice for multisorting.

jsfiddle

html

<table ref="mainTable" className="table table-striped table-bordered table-hover" cellSpacing="0" id="mainTable" data-show-toggle="true" data-show-columns="true" data-search="true" data-pagination="true">
             <thead>
                <tr>
                   <th data-field="state" data-checkbox="true"></th>
                   <th data-field="Customer Name" data-halign="center"
                      data-align="left" data-sortable="true">Customer Name</th>
                   <th data-field="Location Type" data-halign="center"
                      data-align="left" data-sortable="true">Location Type</th>
                   <th data-field="Location" data-halign="center"
                      data-align="left" data-sortable="true">Location</th>
                </tr>
             </thead>
             <tbody>
                <tr>
                   <td></td>
                   <td>Cap Corp</td>
                   <td>Main</td>
                   <td>Norwalk CT 06851</td>
                </tr>
                <tr>
                   <td></td>
                   <td>Cap Corp</td>
                   <td>Other</td>
                   <td>Norwalk CT 06851</td>
                </tr>
                <tr>
                   <td></td>
                   <td>Tel</td>
                   <td>Main</td>
                   <td>Slough SL1 4DX</td>
                </tr>
                <tr>
                   <td></td>
                   <td>Tel</td>
                   <td>Other</td>
                   <td>London W1B 5HQ</td>
                </tr>
             </tbody>
          </table>



<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        <table class="table table-striped table-bordered table-hover"  cellspacing="0" id="modalTable" data-click-to-select="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-pagination="true">
    <thead>
    <tr>
        <th data-field="state" data-checkbox="true"></th>
        <th data-field="name">Name</th>
        <th data-field="stargazers_count">Stars</th>
        <th data-field="forks_count">Forks</th>
    </tr>
    </thead>
            <tbody>
                <tr>
                   <td></td>
                   <td>ala</td>
                   <td>234</td>
                   <td>Norwalk CT 06851</td>
                </tr>
                <tr>
                   <td></td>
                   <td>ala</td>
                   <td>234</td>
                   <td>Norwalk CT 06851</td>
                </tr>
                <tr>
                   <td></td>
                   <td>ala</td>
                   <td>234</td>
                   <td>Slough SL1 4DX</td>
                </tr>
                </tbody>
    </table>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

javascript

$('#mainTable').bootstrapTable({
    showFilter: true,
    showMultiSort: true
});

$('#modalTable').bootstrapTable({
    showFilter: true,
    showMultiSort: true
  });

Solution

  • Your modal table headers are missing the data-sortable="true" attribute:

    <thead>
        <tr>
            <th data-field="state" data-checkbox="true"></th>
            <th data-field="Customer Name" data-halign="center"
                data-align="left" data-sortable="true">Customer Name</th>
            <th data-field="Location Type" data-halign="center"
                data-align="left" data-sortable="true">Location Type</th>
            <th data-field="Location" data-halign="center"
                data-align="left" data-sortable="true">Location</th>
        </tr>
    </thead>