问题描述
在我的Asp.net应用程序中,我有一个Gridview控件并绑定在后面的代码。在客户端我使用
Jquery DataTable版本1.9.4
为了更好的排序,搜索功能,这里我有一个问题数值不正确排序。 我googled,并通过使用 sType:numeric
将解决,但是当我使用这个我的整个工作stoped我的列是在9位置,所以我设置 aTragets
9
以下是
Javascript:
$(document) (function(){
/ pre>
$('#ctl00_ContentPlaceHolder1_GridView3')。dataTable({
bJQueryUI:true,
sPaginationType:full_numbers
//aoColumnDefs :[{sType:numeric,aTargets:[9]}]
});
});
代码nehind:
在Page_PreRenderif(GridView3.Rows.Count> 0)
{
GridView3.UseAccessibleHeader = true;
GridView3.HeaderRow.TableSection = TableRowSection.TableHeader;
}
在pageLoad上:
GridView3.DataSource = sortedDT;
GridView3.DataBind();
解决方案这是我如何解决:
具有项目模板的Gridview :
在项目模板中,他们可能是标签控件,因此转换为我们需要使用
.contents()删除该span标签,即html标签。unwrap();
代码:
$(#Gridview_ID span)。
$('#Gridview_ID').dataTable({
bJQueryUI:true,
sPaginationType:full_numbers,
aoColumns:[{bSortable :false},null,null,{sType:numeric},{sType:date},null,{bSortable:false}]
});
带有界限字段的Gridview:
$('#Gridview_ID').dataTable({
bJQueryUI:true,
sPaginationType:full_numbers,
aoColumns:[{bSortable:false},null,null,{sType:numeric},{sType:date},null,{bSortable:false}]
});
In my Asp.net app, I have a Gridview Control and bind it on code behind.
And on client side I useJquery DataTable version 1.9.4
for better Sorting,Searching functionality, Here i got one problem Numeric value not sorting properly.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 setaTragets
9Here's the JS FIDDLE
Javascript:
$(document).ready(function () { $('#ctl00_ContentPlaceHolder1_GridView3').dataTable({ "bJQueryUI": true, "sPaginationType": "full_numbers" // "aoColumnDefs": [{ "sType": "numeric", "aTargets": [9] }] }); });
Code nehind:On Page_PreRender
if (GridView3.Rows.Count > 0) { GridView3.UseAccessibleHeader = true; GridView3.HeaderRow.TableSection = TableRowSection.TableHeader; }
On pageLoad :
GridView3.DataSource = sortedDT; GridView3.DataBind();
解决方案This is how i solved:
Gridview with Item template:
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();
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}] });
这篇关于Jquery DataTable Sorting数值列不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!