3

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.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 set aTragets 9

Here's the JS FIDDLE

Javascript:

$(document).ready(function () {
    $('#ctl00_ContentPlaceHolder1_GridView3').dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers"
       // "aoColumnDefs": [{ "sType": "numeric", "aTargets": [9] }]

       });
  }); 

enter image description here

enter image description here

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();
3
  • do you have any numeric values separated by comma also? For ex 1,2 ? Commented May 30, 2013 at 11:46
  • @MaVRoSCy: No only decimal values, like `10.5, 13.5' and so on but their is no whitespace nor comma, i tried your solution but still not fixed Commented May 30, 2013 at 13:13
  • can you please paste the table data in a fiddle jsfiddle.net? Commented May 30, 2013 at 13:15

2 Answers 2

3

I think aaSorting is what you have to use

$(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.

See a working fiddle http://jsfiddle.net/6Pxwy/1

Sign up to request clarification or add additional context in comments.

11 Comments

Thank you for reply, its still not sorting properly, but now using "aaSorting": [[ 9, "asc"]], other functionality are working fine,
what exactly doesn't properly? Do you get errors? or is it datatables functionality problems?
also if you have any other initialization code show it also, so that we have a full picture of what you are doing and what might go wrong
I updated my question, i didnt get any error but sorting is not proper, as u can see both images asc/desc order for billinglosthrs column
Thanks i solved it, earlier i was using Item template with a label inside my gridview so its convert into span, now i used BoundFiels and its working fine
|
1

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}]
     });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.