admin管理员组

文章数量:1290935

i am using datatables 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

i am using datatables 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

Share Improve this question edited Oct 17, 2011 at 19:31 Keith.Abramo 6,9652 gold badges33 silver badges46 bronze badges asked Oct 4, 2011 at 10:18 max4evermax4ever 12.1k13 gold badges79 silver badges118 bronze badges 2
  • Would you please post any code which wraps around your table, any div tags etc – Anagio Commented Oct 19, 2011 at 22:02
  • You may want to try adding "sClass": "someclass" to the fixed columns, then in your style sheet set the class to !important and set their width from your style sheet instead of using sWidth. – Anagio Commented Oct 19, 2011 at 22:06
Add a ment  | 

3 Answers 3

Reset to default 3

Try setting "bAutoWidth": false,

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%

If the code listed for the initial question is still being used, I'm thinking the problem may have something to do with the first column being set to take up 100% of the space...

本文标签: javascriptdatatablesnet column width inand pxStack Overflow