[英]How to impose numerical sort with jQuery and dataTables?
我正在使用DataTables jQuery插件。 我正在嘗試啟用排序交互,但在排序時,它按字母順序排序,而不是數字排序。 如-4317.93
所示, -4317.93
顯示在-631
和-456
。 如何使DataTable
以數字方式對列進行排序?
更新的答案
使用最新版本的DataTables,您需要在columnDefs
數組中設置您提供的對象的type
屬性,如下所示:
$('#example').dataTable({
"columnDefs": [
{ "type": "num" }
]
});
請注意,還有許多其他排序方法,可以在文檔中找到
原始答案
您需要將sType
參數添加到列定義中。
例如:
$('#example').dataTable({
"aoColumnDefs": [
{ "sType": "numeric" }
]
});
DataTable文檔中的更多信息: http : //www.datatables.net/plug-ins/sorting
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.