Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatables.net column width in % and px

i am using datatables.net and need to have some columns with fixed width and others to divide the remaning space in %

this is my code

{ "sName": "ragsoc_denom", "sWidth": "100%"},
{ "sName": "piva", "sWidth": "80px"},
{ "sName": "telefono", "sWidth": "100px"},
{ "sName": "indirizzo", "sWidth": "100px"},
{ "sName": "cap", "sWidth": "50px"},
{ "sName": "citta", "sWidth": "50px"},
{ "sName": "id", "sWidth": "70px"}

but it doesn't work, the percentage tables take all available space and the fixed width ones get streched to minimum

like image 528
max4ever Avatar asked Oct 04 '11 10:10

max4ever


2 Answers

Try setting "bAutoWidth": false,

like image 82
Anagio Avatar answered Sep 21 '22 17:09

Anagio


If you do not care how the remaining % is dispersed you could leave it up to datatables by setting the remaining sWidths to null.

If you do care how the remaining % are split up can you do this dynamically at runtime by taking the total static px (in this example 450px) subtract it from the current width of the table and then use that as a guide to determine the remaining percentages for the columns.

For example if i had a datatable that was 1000px

1000 - 450 = 550

I want a column which is 10% of the remaining

550px of 1000px = 55% left so 10% of 55% = 5.5%

like image 28
Keith.Abramo Avatar answered Sep 23 '22 17:09

Keith.Abramo