javascript 数据表排序编号工作不正常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20273325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Datatables sort numbers is not working properly
提问by Digital fortress
I use datatables on my page, it seems to work fine, except that when you do sorting on the number field, it sorts in a weird way, take a look at the illustration
我在我的页面上使用数据表,它似乎工作正常,只是当你对数字字段进行排序时,它以一种奇怪的方式进行排序,看看插图
This one also
这个也
I have tried to place
我试图放置
"aoColumns": [
null,
null,
null,
null,
null,
null,
{ "sType": 'numeric',
"oCustomInfo":{
"decimalPlaces":1,
"decimalSeparator":"."}
},
null
]
But this seems to further disturbs its behaviour as it becomes unsortable. Do you have a clue ?
但这似乎进一步扰乱了它的行为,因为它变得不可排序。你有什么线索吗?
Thanks
谢谢
采纳答案by MaVRoSCy
Your problem is that for some reason the table data are treated as string and NOT as a number. Check the formatting of your values.
您的问题是由于某种原因,表数据被视为字符串而不是数字。检查值的格式。
If fore example you have something like this:
如果例如你有这样的事情:
<table .....>
<tbody>
<tr>
<td><span>1</span></td>
</td>
....
</tbody>
</table>
Then Datatables will treat the value of that column as a string and not as a Number. This is common if you are outputting the text with a framework such as asp .NET.
然后 Datatables 将该列的值视为字符串而不是数字。如果您使用诸如 asp .NET 之类的框架输出文本,这很常见。
See thisfor a similar problem
看到这个类似的问题