javascript Jquery DataTable Sorting Numeric value 列无法正常工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16832139/
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
Jquery DataTable Sorting Numeric value column not working properly
提问by Satinder singh
In my Asp.net app, I have a Gridview Control and bind it on code behind.
And on client side I use Jquery DataTable version 1.9.4for better Sorting,Searching functionality, Here i got one problem Numeric value not sorting properly.
在我的 Asp.net 应用程序中,我有一个 Gridview 控件并将其绑定到后面的代码上。
在客户端,我使用Jquery DataTable version 1.9.4更好的排序、搜索功能,在这里我遇到了一个问题,数值排序不正确。
I googled and come to knw by using sType": "numeric"will solved, but when i use this my whole working stoped my Column is at 9 position so i set aTragets9
我用谷歌搜索并通过使用sType": "numeric"将解决,但是当我使用它时,我的整个工作停止了我的列在 9 位置,所以我设置了aTragets9
Here's the JS FIDDLE
Javascript:
Javascript:
$(document).ready(function () {
$('#ctl00_ContentPlaceHolder1_GridView3').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers"
// "aoColumnDefs": [{ "sType": "numeric", "aTargets": [9] }]
});
});




Code nehind: On Page_PreRender
后面的代码:在 Page_PreRender 上
if (GridView3.Rows.Count > 0)
{
GridView3.UseAccessibleHeader = true;
GridView3.HeaderRow.TableSection = TableRowSection.TableHeader;
}
On pageLoad :
在 pageLoad 上:
GridView3.DataSource = sortedDT;
GridView3.DataBind();
采纳答案by Satinder singh
This is how i solved:
我是这样解决的:
Gridview with Item template:
带有项目模板的 Gridview:
In Item template their might be label control, so it convert into span, we need to remove that span tag ie html tag using .contents().unwrap();
在项目模板中,它们可能是标签控件,因此它转换为跨度,我们需要使用删除该跨度标签即 html 标签 .contents().unwrap();
Code:
代码:
$("#Gridview_ID span").contents().unwrap();
$('#Gridview_ID ').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns": [{ "bSortable": false }, null, null, { "sType": "numeric" }, { "sType": "date" }, null, { "bSortable": false}]
});
Gridview with Bound Field:
带有绑定字段的网格视图:
$('#Gridview_ID ').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns": [{ "bSortable": false }, null, null, { "sType": "numeric" }, { "sType": "date" }, null, { "bSortable": false}]
});
回答by MaVRoSCy
I think aaSortingis what you have to use
我认为aaSorting是你必须使用的
$(document).ready(function () {
$('#ctl00_ContentPlaceHolder1_GridView3').dataTable({
"aaSorting": [[ 9, "asc"]], /*row count starts from 0 in datatables*/
"bJQueryUI": true,
"sPaginationType": "full_numbers"
// "aoColumnDefs": [{ "sType": "numeric", "aTargets": [9] }]
});
});
UPDATE
更新
The problem was as stated in my comment It clearly does not understand the numeric datatype of the column. Your problem is that inside your ... you had also text.
问题如我的评论中所述It clearly does not understand the numeric datatype of the column。你的问题是在你的......里面你也有文字。
See a working fiddle http://jsfiddle.net/6Pxwy/1
看到一个工作小提琴http://jsfiddle.net/6Pxwy/1

