javascript - Complex column widths with Jquery Datatables -


i have created datatable following code

$(document).ready( function () {     $('#data-table').datatable( {         "bfilter": false,         "scrolly": 300,         "scrollx": true,         "paging":   false,         "ordering": false,         "info":     false,         "columndefs": [         { "width": "20%", "targets": 0 }     ]      }); } ); 

note have widths set 20% each of columns. question how specify width column 1 while still being able set width rest of columns?

i've seen examples on datatable website:

$('#example').datatable( {   "columns": [     { "width": "20%" },     null,     null,     null,     null   ] } ); 

but not think work me because looks if require me know how many columns table has in advance, , user requirements require number of columns variable.

try replacing columndefs part (and adding appropriate percentages):

"columndefs": [         { "width": "(percentage)%", "targets": "_all" }         { "width": "(other percentage)%", "targets": 0 } ] 

this set first column 1 width , others different width.

targets define column affected. setting integer affect columns starting left right (i.e. '"targets": [0, 1]' affect leftmost , second-leftmost columns). negative integers affect columns right left. string "_all" affect columns.


Comments