0

I know it's been discussed here before so i went over all the answers first but still have some problems.

I have a table with a comments column with much more text then the others....i want to set fixed size to all the columns and only for the comments column to set a different size - or just to break line - don't know yet what is the best way... hope you can help me.

I didn't manage to get this code to work :

   bAutoWidth: false , 
  "aoColumnDefs": [
  { "sWidth": "20%", "aTargets": [ 0 ] },
  { "sWidth": "5%", "aTargets": [ 1 ] },
  { "sWidth": "10%", "aTargets": [ 2 ] },
  { "sWidth": "5%", "aTargets": [ 3 ] },
  { "sWidth": "40%", "aTargets": [ 4 ] },
  { "sWidth": "5%", "aTargets": [ 5 ] },
  { "sWidth": "15%", "aTargets": [ 6 ] }
  ],

Here is a sample of the project ( in production there are more columns with much more text) Plunker

4
  • Have a look at this link datatables.net/reference/option/columns.width Commented Apr 24, 2017 at 7:17
  • Thanks - as i mentioned - i looked over it already. Commented Apr 24, 2017 at 7:25
  • Tried using same code provided in link? is it working? Commented Apr 24, 2017 at 7:53
  • Yes, i've tried - it's the first thing that i've done Commented Apr 24, 2017 at 8:07

1 Answer 1

4

First; you need to make a small change in your css file;

#example > tbody > tr > td {
    white-space: nowrap;
}

will be;

#example > tbody > tr > td {
    word-break: break-all;
}

This change will break the line for long texts. And if you still want to change the width of a specific column, you should use columnDefs property of DataTables. Like;

"columnDefs": [{ "width": "200px", "targets": 3 }]

Modified example: Plunker

Sign up to request clarification or add additional context in comments.

2 Comments

How can i set the size to be lower then 10px? all above 10 px works fine.... below 10 px - nothing is changing
It can't be lower than the header (Comments) width.

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.