How to wrap cell text in a table?

How to wrap cell text in a table?

dtUser2011dtUser2011 Posts: 11Questions: 0Answers: 0
edited February 2013 in General
Hi,

I'm new to GUI development, and I'm using the DataTables API to create a table. I have a table with four cells, and the last two cells can have very long strings. Do you know how I can wrap the text in the cells? Currently, the long text just spews across the cells. Here is my current code:

HTML:



Server Port Name
Server Node Name
Storage Port Name
Storage Node Name




Javascript:

var linkOptions = {
"fnHeaderCallback": function( nHead, aData, iDisplayIndex ) {
$('td:eq(0)', nHead).css("background-color","transparent");
},
"bPaginate" : false,
"bFilter" : false,
"bInfo" : false,
"bAutoWidth" : false,
"aaData" : [],
"aaSorting": [[ 1, "alphanumeric-asc" ]],
"aoColumns" : [
{
"sTitle" : serverPortNameTitle,
"sWidth" : "230px",
"mDataProp" : "serverPortName",
"sType" : "string"
}, {
"sTitle" : serverNodeNameTitle,
"sWidth" : "230px",
"mDataProp" : "serverNodeName",
"sType" : "string"
}, {
"sTitle" : storagePortNameTitle,
"sWidth" : "230px",
"mDataProp" : "storagePortName",
"sType" : "string"
}, {
"sTitle" : storageNodeNameTitle,
"sWidth" : "230px",
"mDataProp" : "storageNodeName",
"sType" : "string"
}
]
};

var table_id = DOWNLINK_NAMESERVER_PORTS_TABLE_ID + '-' + portId;
return $(table_id).dataTable(linkOptions);


Thanks for your help in advance!

Replies

  • equisdeequisde Posts: 34Questions: 0Answers: 0
    Hello,

    Take a look at this thread

    http://www.datatables.net/forums/discussion/12691/table-content-width-exceeds-header-width#Item_10
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Also, can you link to a test case please? Table cells should generally wrap automatically.

    Allan
  • dtUser2011dtUser2011 Posts: 11Questions: 0Answers: 0
    Hi Allan and Equisde,

    Thanks for your quick response! I thought the table cells should wrap automatically, too, but it doesn't. I've attached a link to the code here: http://live.datatables.net/uhunib/2/edit
  • webmariowebmario Posts: 3Questions: 0Answers: 0
    hi, you can try giving the td´s following css:
    td {word-wrap: break-word}
  • dtUser2011dtUser2011 Posts: 11Questions: 0Answers: 0
    Thanks -- that worked!
This discussion has been closed.