简体   繁体   中英

DataTables - Sort by column 10 then by column 9 on initialization

In my datatables I can sort by a specific column on initialization by using the code below.

jQuery(document).ready(function($) {
  var dataTable = $('#contracts-datatable').DataTable({
   bLengthChange: false,
   "pageLength": 10,
   "pagingType": "simple",
   "order": [[ 9, "asc" ]], // <<--- Sorting by column 9

What I'd like to do is sort by column 10 first then sort the data by column 9.

On my website when I sort like this it arranges data more efficiently - how can I run this on initialization of my dataTables?

I tried..

jQuery(document).ready(function($) {
  var dataTable = $('#contracts-datatable').DataTable({
   bLengthChange: false,
   "pageLength": 10,
   "pagingType": "simple",
   "order": [[ 10, "asc" ], [ 9, "asc"]],

http://mobilereactor.co.uk/shop/mobile-phones/apple-iphone-5c-8gb-white-deals/

But it doesn't work. These are also hidden columns if that makes any difference.

What should happen with this column sort is I should end up with all the initial cost (free) mobiles on the first page and they should be ordered by their monthly price ascending.

Try "order": [[ 10, 'asc' ], [9, 'asc' ]]

           "order": [[ 10, 'asc' ], [9, 'asc' ]]

Codepen URL for reference - http://codepen.io/nagasai/pen/yJOaLv

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