2017-08-03 19 views
0

我面臨着整理/訂購一種特殊類型的格式化的數字與https://datatables.net/一個問題排序格式的數字。我有一個像111.111.11146.323.345,88數中的錢數。數據表 - 用點

我試過使用類型:num-fmt但沒有成功。當我在我的項目中添加這種類型的屬性我甚至不能排序了。沒有什麼happend像我hvae訂貨禁用。

希望你們能幫幫我! TY

private initVolumenTable() { 
    $('#volumen-table').DataTable({ 
     columnDefs: [ 
      {targets:3, type: 'num-fmt' } 
     ], 
     "scrollY": "400px", 
     "scrollCollapse": false, 
     "paging": false, 
     "ordering": true,   
    }); 

在的jsfiddle順序發生,但其不正確..

所以我創建一個:JsFiddle。 :)

回答

0

試試這個代碼:

$(document).ready(function() { 
    $('#example').dataTable(); 
    jQuery.extend(jQuery.fn.dataTableExt.oSort, { 
     "numeric-comma-pre": function (a) { 
      // prepare number 
      a = +(a.replace(",", ".")); 
      a = (isNaN(a)) ? Number.MAX_VALUE : a; 
      return a; 
     }, 
     "numeric-comma-asc": function (a, b) { 
      return ((a < b) ? -1 : ((a > b) ? 1 : 0)); 
     }, 
     "numeric-comma-desc": function (a, b) { 
      return ((a < b) ? 1 : ((a > b) ? -1 : 0)); 
     } 
    }); 
});