DataTable 数字排序问题

问题:DataTable 的默认排序功能是按字符来排的。在js里,把数字当字符串来排序会很大的问题,例如:"2" > "11" 返回的是 true

解决办法:

设置 DataTable 列类型值类型的办法:https://datatables.net/reference/option/columns.type#Description

$('#example').dataTable( {
  "columnDefs": [
    { "type": "num", "targets": [3,4,5] }
  ]
} );
参数说明
参数 类型 说明
type string 列数据类型,可选值:date, num, num-fmt, html-num, html-num-fmt, html, string
targets mixed 目标列,下标从0开始,类型可填 数字 或 数组 或'_all',示例:3, [4,5,6], '_all'

https://www.cnblogs.com/tujia/p/11026730.html 

猜你喜欢

转载自www.cnblogs.com/tujia/p/11026730.html
今日推荐