1

I have a Datatable, at run time it will create and bind to Gridview Control, So I dnt know how many columns it would be,
Now i want to allow sorting only for 2nd Columns .i.e Name rest all will be disable.

 $('#ctl00_ContentPlaceHolder1_GridView1').dataTable({
     "bJQueryUI": true,
         "sPaginationType": "full_numbers",
     // "aoColumns": [{ "bSortable": false }, null]
 }); 

JS FIDDLE

1 Answer 1

1

That's an interesting problem. The datatables forum has a discussion very closely related to the issue you are encountering.

http://datatables.net/forums/discussion/11967/aocolumns-when-number-of-columns-vary/p1

Allan Jardine, creator of datatables, is part of the discussion, and his first reply recommended using aoColumnDefs and showed how you could do aTargets: [ '_all' ] to take care of the issue of variable number of columns.

So based on a quick scan of the discussion on the datatables forum, here's a fiddle that might get you close to what you are looking for:
http://jsfiddle.net/nLYLv/

 $('#ctl00_ContentPlaceHolder1_GridView1').dataTable({
     "bJQueryUI": true,
         "sPaginationType": "full_numbers",
         "aoColumnDefs": [
            {"aTargets": [ 1 ], "bSortable": true },
            {"aTargets": [ '_all' ], "bSortable": false }  
        ], 
       // force the arrow to show on 2nd column
       "aaSorting": [[1,'asc']]
 });
Sign up to request clarification or add additional context in comments.

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.