最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to sort only certain columns - Stack Overflow

programmeradmin6浏览0评论

I am using jQuery DataTables plugin to sort table data. I have four columns: Name, Position, Office and Age. What I want is user to be able to sort only Name and Age columns, not all the columns. But I am not able to stop sorting on OTHER columns. Can you please suggest something?

I am using jQuery DataTables plugin to sort table data. I have four columns: Name, Position, Office and Age. What I want is user to be able to sort only Name and Age columns, not all the columns. But I am not able to stop sorting on OTHER columns. Can you please suggest something?

Share Improve this question edited Jul 20, 2015 at 4:54 Gyrocode. 58.9k16 gold badges156 silver badges191 bronze badges asked Jul 17, 2015 at 6:50 love thakkerlove thakker 4702 gold badges13 silver badges29 bronze badges 1
  • Here is my fiddle. – love thakker Commented Jul 17, 2015 at 6:51
Add a ment  | 

1 Answer 1

Reset to default 9

This code disable sorting, 0 - index of column. For old version

aoColumnDefs: [
  {
     bSortable: false,
     aTargets: [ 0 ]
  }
]

for DataTables 1.10+

columnDefs: [
   { orderable: false, targets: 0 }
]

Especially for example, you need this

$(document).ready(function() {
    $('#example').dataTable( {
        "order": [[ 0, "desc" ]],
        "aoColumns": [
           null,
           { "bSortable": false },
           { "bSortable": false },
           null
         ]
    } );
} );

fiddle

发布评论

评论列表(0)

  1. 暂无评论