禁用对 bootstrap-table 中隐藏列的排序

Disable sorting on hidden columns in bootstrap-table

我正在使用 bootstrap-table with the table-multiple-sort 扩展来制作 sortable table。

this example中,当您隐藏某些列时,隐藏列的排序将被禁用。

但是,当我应用该插件时,排序仍然发生在隐藏列上。看到这个 JS Fiddle:

jsfiddle

<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>

如何禁用对隐藏列的排序?

显示是因为你没有设置选项sortPriority 通过设置这将解决错误。

Check working fiddle here

你的 JS 应该是这样的
示例取自问题中给出的 jsfiddle。

$('#mainTable').bootstrapTable({
    showFilter: true,
    showMultiSort: true,
    sortPriority: [{
        "sortName": "Location",
        "sortOrder": "desc"
    }]
});