Wrap text on any character
Wrap text on any character
martin@sommer.net
Posts: 15Questions: 0Answers: 0
Allen,
How can I make your bAutoWidth function wrap long text lines on any character, vs just special characters?
For example, I would like the following string to wrap at a column width of 25:
5885d80a13c0db1f998ca054efbdf2c78a435fe324eec2511727fbf3e9efcec46b86d398a4c8cec6f5de2a9979eb86d42c398a4c8cecde2a9979
Thanks,
Martin
How can I make your bAutoWidth function wrap long text lines on any character, vs just special characters?
For example, I would like the following string to wrap at a column width of 25:
5885d80a13c0db1f998ca054efbdf2c78a435fe324eec2511727fbf3e9efcec46b86d398a4c8cec6f5de2a9979eb86d42c398a4c8cecde2a9979
Thanks,
Martin
This discussion has been closed.
Replies
This isn't actually how bAutoWidth works. What it does is to find the longest string in each column, and then put them into a temporary table where the browser will calculate the width needed for the display of each column (rather than re-implementing the HTML table width calculations - which are horribly complicated for something like this, and different in the different browsers...). DataTables will then read the calculated values and use them for it's column widths.
What it won't do is to break a string up into chunks (for example add hyphens) - which is what is needed to "wrap" text like that above into multiple lines. In fact, you can see this in action in this forum, where the string can have no break point in it, so it's just overflowing the discussion column!
As such, this is more of a browser rendering thing, that DataTables specific. So what I think you might need to do is chunk the data into sections of 25.
There has also been some discussion previously about using ellipsis with DataTables which might help you (alternative option). There are a couple of discussions about it.
http://datatables.net/forums/comments.php?DiscussionID=208
http://datatables.net/forums/comments.php?DiscussionID=30
http://datatables.net/forums/comments.php?DiscussionID=132
Regards,
Allan
This may be a browser thing, and I may have to put breaks into the data on the server side. Using an ellipsis is not an option, as not the whole string would show.
For the sake of discussion, lines with special characters like "/", "-", etc. will wrap, but a pure alphanumeric will not.
For example, this string will wrap twice:
5885d80a13c0/db1f998ca054efbdf2c78a4-35fe324eec2511727fbf3e9
... but, this will not:
5885d80a13c0db1f998ca054efbdf2c78a435fe324eec2511727fbf3e9
Do you know where this is determined?
Thanks again,
Martin
PHP wordwrap() did the trick!
$sOutput .= '"'.wordwrap(addslashes($aRow['my_column']),30,'\n',true).'",';
Thanks again,
Martin
The method by which browsers use to calculate where to put a break in the text differs from browser to browser - but typically it's which space, slash or a hyphen (older versions of Firefox didn't break on the hyphen, not sure if new versions do - or what IE does) - or a few other characters. It's probably in the HTML spec somewhere... (maybe).
Regards,
Allan