I am using DataTables formatting on my tables. I use Server Side processing and fixed header and footer.
I am seeing inconsistencies in the way the <td>
values are displayed when the text is long for different browsers.
- Chrome I get a usable scrollbar (the expected outcome)
- IE I see the scrollbar, but can't use it
- Firefox the long text just overflows to the right
I know that if I can surround the <td>Long Text</td>
in a <div class="Scrollable"><td>Long Text</td></div>
that this would fix it. I have done this on other tables that are not using DataTable formatting. I just can't seem to get it to work.
Here's how I'm initializing my table:
<script type="text/javascript" class="init">
$.fn.dataTable.ext.buttons.export =
{
className: 'buttons-alert',
"text": "Export All Test",
action: function (e, dt, node, config)
{
alert('Export All Test');
}
};
$(document).ready(function ()
{
// Setup - add a text input to each footer cell
$('#DataTable tfoot th').each(function ()
{
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
});
var table = $('#DataTable').DataTable({
"lengthMenu": [[25, 50, 75, 100, 150,-1], [25, 50, 75, 100, 150,'All']],
"dom": '<"top"Bifl<"clear">>rt<"bottom"i<"clear">>',
"buttons": [{
extend: 'collection',
text: 'Selection',
buttons: ['selectAll', 'selectNone']
}, {
extend: 'collection',
text: 'Export',
buttons: ['export', 'excel', 'csv', 'pdf', { extend: 'excel',
text: 'Export Current Page',
exportOptions: {
modifier: {
page: 'current'
}
},
customize: function (xlsx)
{
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr('s', '7');
}
},
{
text: 'Export All to Excel',
action: function (e, dt, button, config)
{
dt.one('preXhr', function (e, s, data)
{
data.length = -1;
}).one('draw', function (e, settings, json, xhr)
{
var excelButtonConfig = $.fn.DataTable.ext.buttons.excelHtml5;
var addOptions = { exportOptions: { 'columns': ':all'} };
$.extend(true, excelButtonConfig, addOptions);
excelButtonConfig.action(e, dt, button, excelButtonConfig);
}).draw();
}
}]
}
],
"fixedHeader": {
header: true,
footer: true
},
"select": true,
"processing": true,
"serverSide": true,
"ajax": {
"url": "./ServerSide.php",
"type": "POST"
},
initComplete: function ()
{
var api = this.api();
// Apply the search
api.columns().every(function ()
{
var that = this;
$('input', this.footer()).on('keyup change', function ()
{
if (that.search() !== this.value)
{
that
.search(this.value)
.draw();
}
});
});
}
});
//This is what I've tried to get the DIV in place, but it doesn't work.
$('#DataTable tbody td').wrap('<div class="Scrollable"></div>');
});
</script>
I have this in my CSS This should allow the scrollbar to be present and usable in all browsers
div.Scrollable {
overflow-x: auto;
width: 100%;
}
This should make the Long Text
wrap around and increase the height of the row to accommodate it.
.selected {
background-color: #999999 !important;
color: #fff;
overflow: visible !important;
white-space: normal !important;
word-wrap: break-word;
max-height: 500px;
}
I don't know enough about jquery to figure this out.
EDIT
I have tried this as well:
$('#DataTable td').wrap(function(){ return "<div class='Scrollable'></div>"});
EDIT 2
I've just realized I've been trying to do this backward. I need the <td></td>
wrapped around the <div></div>
so that it'll be like <td><div class="Srcollable">Text Value</div></td>
Here's a fiddle of the problem. It's not a problem in Chrome, though, it is a problem in IE and Firefox.
The first and third rows are without the <div>
the second row has the <div>
and has the usable scrollbar.
I just figured it out!
In my modified version of the ssp.class.php file (from here) I updated the data_output function so that it will add the
<div>
around the values that it returns so that when the DataTable is initialized the<div>
is already in place and the<td>
is placed around it.The function now looks like this: