2013-02-13 55 views
1

因此,我使用Datatables插件(http://datatables.net/)對我的表格中的數據進行排序。Javascript數據表 - 插件問題

我存儲的數據包括數字(22.34),貨幣(223,400美元)和格式化數字(233,623)。網站上有一個用於排序插件的部分(http://datatables.net/plug-ins/sorting)。

我花了最近2個小時試圖讓這個工作,但不管我嘗試什麼都不斷收到錯誤。

這裏是我的代碼:

包括如下腳本:

<script src="assets/js/dataTables.plugins.js"></script> 

其中包含以下內容:

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

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

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

然後,主代碼:

<script> 
    $(document).ready(function() { 

    var oTable = $('#sample_1').dataTable({ 
      "sDom": "<'row-fluid'<'span4'l><'span4 tbl_time_frame'><'span4'f>r>t<'row-fluid'<'span4'i><'span4'><'span4'p>>", 
      "sPaginationType": "bootstrap", 
      "aoColumns": [ 
       { "sType": "numeric" }, 
       null, 
       { "sType": "formatted-num"}, 
       { "sType": "numeric"}, 
       null, 
       null, 
       null, 
       null, 
       null 
      ], 
      "oLanguage": { 
       "sLengthMenu": "_MENU_ records per page", 
       "oPaginate": { 
        "sPrevious": "Prev", 
        "sNext": "Next" 
       } 
      }, 
      "fnInitComplete": jQuery('.tooltips').tooltip() 
    }); 
}); 

我在頁面加載以下錯誤:

Uncaught TypeError: Cannot read property 'oSort' of undefined 

然後當我點擊第三排我收到以下錯誤交替:

Uncaught TypeError: Property 'formatted-num-asc' of object #<Object> is not a function jquery.dataTables.js:4038 
Uncaught TypeError: Property 'formatted-num-desc' of object #<Object> is not a function 

誰能幫助?

乾杯

回答

2

的問題是,在這些文件中包含的順序做。我改變了這一點,它解決了這個問題。

+0

你能詳細闡述一下嗎?你提到「我改變了這個並解決了它」,但你改變了什麼? – Kiran 2016-02-29 23:36:13

0

我試圖解決同樣的問題時,通過dataTables.js使用naturalSort.js時遇到了這個舊帖子。對我來說有效的是在dataTables.js之後移動naturalSort.js。簡單的改變,但解決了問題。