Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  152] [ 3]  / answers: 1 / hits: 90216  / 8 Years ago, fri, september 23, 2016, 12:00:00

We are using the Scroller plugin for our jquery data table to allow virtual scrolling. However, we have requirement to support text wrapping inside a cell, as user would like to view the entire text instead of truncated one. I observed that it does not wrap the text by default. Is there a way to support this feature? Any possible workaround?



Fiddler
https://jsfiddle.net/Vimalan/2koex0bt/1/



html Code:



<table id=example class=display cellspacing=0 width=100%></table>


js code:



var detailsSample = DataTables and its extensions are extremely configurable libraries and almost every aspect of the enhancements they make to HTML tables can be customised. Features can be enabled, disabled or customised to meet your exact needs for your table implementations.
var dataList = [];

for (var i=1; i<=500; i++)
{
var dataRow = {};

dataRow.ID = i;
dataRow.FirstName = First Name + i;
dataRow.LastName = Last Name + i;

if (i%5 ==0)
{
dataRow.Details = detailsSample;
}
else
{
dataRow.Details = Large text +i;
}
dataRow.Country = Country Name;

dataList.push(dataRow);
}

$('#example').DataTable( {
data: dataList,
deferRender: true,
scrollX: true,
scrollY: 200,
scrollCollapse: true,
scroller: true,
searching: false,
paging: true,
info: false,
columns: [
{ title: ID, data: ID },
{ title: First Name, data: FirstName },
{ title: Change Summary, data: LastName},
{ title: Details, data: Details, width: 400px },
{ title: Country, data: Country }
]
} );


Expectation



In the above table, the Details column should always have a width of 400px and the text in that column should wrap.



Any suggestion will be greatly appreciated.


More From » jquery

 Answers
14

Found the solution by wrapping the column data in a div and setting the white-space, width css properties for the div.



Fiddler:https://jsfiddle.net/Vimalan/2koex0bt/6/



JS



$('#example').DataTable( {
data: dataList,
deferRender: true,
scrollX: true,
scrollY: 200,
scrollCollapse: true,
scroller: true,
searching: false,
paging: true,
info: false,
columns: [
{ title: ID, data: ID },
{ title: First Name, data: FirstName },
{ title: Change Summary, data: LastName},
{ title: Details, data: Details },
{ title: Country, data: Country }
],
columnDefs: [
{
render: function (data, type, full, meta) {
return <div class='text-wrap width-200'> + data + </div>;
},
targets: 3
}
]
} );


CSS



.text-wrap{
white-space:normal;
}
.width-200{
width:200px;
}

[#60619] Wednesday, September 21, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austonjuancarlosb

Total Points: 238
Total Questions: 89
Total Answers: 99

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;