简体   繁体   中英

How to prevent sorting on specific table column - DataTable?

I don't want to sort my action column, so I did :

<th class="no-sort" >Actions</th>

and update my JS like this

$('table').DataTable( {
    "bLengthChange": true,
    "Filter": true,
    "Info": true,
    "bSort": true,
    "bPaginate": false,
    "searchHighlight": true,
    "aoColumnDefs": [{
        "bSort": false,
        "aTargets": ["no-sort"]
    }]
} );

I still see that it is sortable. 🤦🏻‍♂️

在此处输入图片说明

How do I stop that ?

The correct property is bSortable , not bSort . See the documentation

"aoColumnDefs": [{
  "bSortable": false,
  "aTargets": ["no-sort"]
}]

Also note that from your use of aoColumnDefs it appears you're using a very old version of DataTables; at least 5 years old in fact. I'd suggest upgrading it when possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM