Satinder singh
Satinder singh

Reputation: 10198

How to disable sorting JQuery DataTable with asp.net Gridview

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

Upvotes: 1

Views: 939

Answers (1)

mg1075
mg1075

Reputation: 18155

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

Upvotes: 1

Related Questions