2017-01-16 158 views
2

我與多列排序的DataTable和它的作品,但我需要:dataTable的多列排序與「ASC」和「DESC」

第一列「ASC」和第二列說明 - >如何這可能嗎?

這裏是我的小提琴:https://jsfiddle.net/zukii/Lucq6vc5/28/

在這撥弄列「等級」被自動默認排序「ASC」,然後列「價格」應該是自動的「遞減」

var mytable = $('table.dt-tarif').dataTable({ 
    "paging": false, 
    "info":  false, 
    "searching": false, 
    "order": [[ 3, "desc" ]], 

    "aoColumnDefs": [ 
     { 
      "bSortable": false, 
      "aTargets": [0] 
     }, 
     { 
      "type": "currency", targets: 3 
     }, 
     { 
      targets: [ 3 ], 
      orderData: [3, 4] 
     } 
    ], 

    "language": { 
     "lengthMenu": "Zeige _MENU_", 
     "zeroRecords": "Keine Entwürfe vorhanden!", 
     "info": "Seite _PAGE_ von _PAGES_", 
     "infoEmpty": "Es konnte kein Entwurf gefunden werden.", 
     "infoFiltered": "", 
     "search": " ", 
     "paginate": { 
      "first": "Erste", 
      "last": "Letzte", 
      "next": "Vor", 
      "previous": "Zurück" 
     }, 
    } 
}); 

感謝和問候;)

+0

它應該是 - >最好的評價與最低的價格! – zukii

回答

0

您需要使用一個二維數組來實現多列排序歸檔結果。

var table = $('table.dataTable').DataTable(); 
table 
    .order([ 3, 'asc' ],[ 4, 'desc' ]) 
    .draw(); 

進一步可以改變格式[columnIndex, 「ASC | DESC」](例如[1, 「降序」]用於分揀

解撥弄:https://jsfiddle.net/ShirishDhotre/a3utn0ek/7/

。檢查這是否有助於關閉你的問題

0

這一個現在工作完美:)

https://jsfiddle.net/zukii/Lucq6vc5/37/

jQuery.extend(jQuery.fn.dataTableExt.oSort, { 
"currency-pre": function (a) { 
    a = (a==="-") ? 0 : a.replace(/[^\d\-\.]/g, ""); 
    return parseFloat(a); 
}, 

"currency-asc": function (a, b) { 
    return a - b; 
}, 

"currency-desc": function (a, b) { 
    return b - a; 
} 
}); 

jQuery.extend(jQuery.fn.dataTableExt.oSort, { 
    "currency": function (a) { 
    var x = a.replace(",", ".").replace("€", ""); 
    return parseFloat(x); 
    }}); 

var mytable = $('table.dt-tarif').dataTable({ 
    "paging": false, 
    "info":  false, 
    "searching": false, 
    "order": [[ 3, "desc" ]], 

    "aoColumnDefs": [ 
     { 
      "bSortable": false, 
      "aTargets": [0] 
     }, 
     { 
      "type": "currency", targets: 3 
     }, 
     { 
      targets: [ 3 ], 
      orderData: [3, 4] 
     } 
    ], 

    "language": { 
     "lengthMenu": "Zeige _MENU_", 
     "zeroRecords": "Keine Entwürfe vorhanden!", 
     "info": "Seite _PAGE_ von _PAGES_", 
     "infoEmpty": "Es konnte kein Entwurf gefunden werden.", 
     "infoFiltered": "", 
     "search": " ", 
     "paginate": { 
      "first": "Erste", 
      "last": "Letzte", 
      "next": "Vor", 
      "previous": "Zurück" 
     }, 
    } 
});