I have the following DataTable (full-width css class sets width = 100%)
<table class="datatable full-width">
<thead>
<th>LOB</th>
<th>Creditor Line 1</th>
<th>Creditor Line 2</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th></th>
</thead>
<tbody>
...
</tbody>
</table>
Javascript:
var profileTable =
$(".datatable").dataTable({
"iDisplayLength": 25,
"bDestroy": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bAutoWidth": false
});
Everything works fine until there is a record with a long text string...when a record appears with really long text, the data table overflows on the right of the page. (See Screenshot Below, the red line is where the page should end) http://i1109.photobucket.com/albums/h430/tbarbedo/overflow.jpg
Can someone tell me how to either wrap the text in the cells or prevent this overflow issue?
I've tried via 'table-layout: fixed'...this prevents the overflow but sets all of the columns to the same width.
Thanks
You can try setting the
word-wrap
however it doesn't work in all browsers yet.Another method would be to add an element around your cell data like this:
Then add some css like this:
I'm way late here, but after reading @Greg Pettit's answer and a couple of blogs or other SO questions I unfortunately can't remember I decided to just make a couple of dataTables plugins to deal with this.
I put them on bitbucket in a Mercurial repo. I follwed the fnSetFilteringDelay plugin and just changed the comments and code inside, as I've never made a plugin for anything before. I made 2, and feel free to use them, contribute to them, or provide suggestions.
dataTables.TruncateCells - truncates each cell in a column down to a set number of characters, replacing the last 3 with an ellipses, and puts the full pre-truncated text in the cell's title attributed.
dataTables.BreakCellText - attempts to insert a break character every X, user defined, characters in each cell in the column. There are quirks regarding cells that contain both spaces and hyphens, you can get some weird looking results (like a couple of characters straggling after the last inserted
character). Maybe someone can make that more robust, or you can just fiddle with the breakPos for the column to make it look alright with your data.
I faced the same problem of text wrapping, solved it by changing the css of table class in DT_bootstrap.css. I introduced last two css lines table-layout and word-break.
The same problem and I solved putting the table between the code
Using the classes "responsive nowrap" on the table element should do the trick.
You can just use render and wrap your own div or span around it. TD`s are hard to style when it comes to max-width, max-height, etc. Div and span is easy..
See: https://datatables.net/examples/advanced_init/column_render.html
I think a nicer solution then working with CSS hacks which are not supported cross browser.