当前位置 : 主页 > 网页制作 > JQuery >

jquery – 如何禁用数据表中只有一个特定列的排序?

来源:互联网 收集:自由互联 发布时间:2021-06-15
假设我有如下表格: And I want to disable sorting of Action Column !--index.html-- table class="table table-striped table-bordered post-list-table" id="table" thead tr thTitle/th thCreated At/th thAction/th /tr /thead/table!--Script
假设我有如下表格:

And I want to disable sorting of Action Column

<!--index.html-->      
<table class="table table-striped table-bordered post-list-table" id="table" >
  <thead>                      
    <tr>
      <th>Title</th>
      <th>Created At</th>
      <th>Action</th>
    </tr>
  </thead>
</table>

<!--Script.js-->
$('#table').DataTable();
尝试添加: columns.orderable

"columnDefs": [
    { "orderable": false, "targets": 2 }
  ]

JSFiddle Here

<!--Script.js-->
$('#table').DataTable( {
"columnDefs": [
    { "orderable": false, "targets": 2 }
  ]
  });
<script src="http://img.558idc.com/uploadfile/allimg/210615/22450T613-0.jpg"></script>
<script src="http://img.558idc.com/uploadfile/allimg/210615/22450V304-1.jpg"></script>
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"/>

<table class="table table-striped table-bordered post-list-table" id="table" >
  <thead>                      
    <tr>
      <th>Title</th>
      <th>Created At</th>
      <th>Action</th>
    </tr>
  </thead>
</table>
网友评论