javascript - bootstrap-table 中的 table-multiple-sort 不适用于一页中的多个表

标签 javascript jquery twitter-bootstrap twitter-bootstrap-3 bootstrap-table

我使用 bootstrap-table和扩展 table-multiple-sort .当我在一页中有两个表时(在我的例子中,第二个表在模式窗口中),在第二个表中我没有任何选择进行多重排序。

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
  });

最佳答案

您的模态表格标题缺少 data-sortable="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>

关于javascript - bootstrap-table 中的 table-multiple-sort 不适用于一页中的多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32504520/

相关文章:

javascript - Raspberry Pi 的 PHP/HTML 通信

javascript - 从上传的 CSV 文件创建数据表

javascript - 通过 JavaScript 类处理时,序列化时表单字段为空

jquery 验证 has-error 类设置

twitter-bootstrap - 鲍尔 : install fork of Bootstrap

javascript - 即使使用 Google Charts Tools 饼图,值 = 0,也会在图例中显示项目

javascript - 实现教堂数字和后继函数

javascript - Leaflet图层控件不显示图层

javascript - 如何仅使用 Vanilla Javascript 在不知道其位置的情况下定位子节点

javascript - jQuery fadeIn() 间隔多个 div