5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

簡単に表の検索やソートができるDataTablesでデフォルトソート

Posted at

便利なjsでデータを簡単に表示できるDataTablesですが、
デフォルトソートの仕方で結構迷ったのでメモ。

試行錯誤


columnDefs: [
{ targets: 0, ordering: 1 },
]

や

"order": [[0, "asc" ]]

や

"order": [[ 0, 'asc' ], [ 1, 'asc' ]]

や

"aoColumnDefs": [
      { "iDataSort": 1, "aTargets": [ 0 ] }
          ]

や

"aoColumnDefs": [
{ "asSorting": [ "desc" ], "aTargets": [1]},
]

でもダメ。。

下記で解決しました。。

解決版

javascript

$(document).ready(function() {
    $('#example').dataTable( {
        "aaSorting": [[ 0, "desc" ]]
    } );
} );

0列目を、降順に。

参考:http://legacy.datatables.net/release-datatables/examples/basic_init/table_sorting.html

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?