datatables print not presenting list elements properly
I have a table with cells that contain list elements, the problem is that when I print the table I lose the list elements and the text becomes very hard to read. see the images.
here is my js to create a datatable, you can just focus on the buttons part.
$(document).ajaxSuccess(function() {
qxGenerateDataTables();
});
function qxGenerateDataTables() {
$("table.dataTable:not(table.dataTableProcessed)").each(function() {
var $this = $(this);
var paganation = !$this.hasClass("no-pagination");
var title = $this.attr ("data-file-name");
var excel= !$this.hasClass("no-excel");
var table = $this.DataTable({
"bPaginate": paganation,
"bSort": true,
stateSave: true,
ordering : true,
searching: true,
fixedHeader: true,
columnDefs : [ {
orderable : false,
targets : "no-sort"
} ]
,
dom:'B<"wrapper"iftlp>',
buttons: [
{
extend: 'excelHtml5',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa-file-excel-o fa-2x"></i>',
titleAttr: 'Excel',
title: title,
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr( 's', '55' );
}
},
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>'
}
]
});
table.buttons().container().appendTo( '#qxDatatable_wrapper .col-sm-6:eq(0)' );
//Surround the table with an outer div, to have the horizontal scroll working properly.
var wrapperDiv = $("<div>", {style:"overflow:auto; width: 100%;"});
$this.before(wrapperDiv);
wrapperDiv.append($this);
//Mark this table as processed.
$this.addClass('dataTableProcessed');
//Just hide the button for now until we find a better way.
if (!excel){
$('.fa-file-excel-o').css( 'display', 'none' );
}
//Hide the table info if pagination is disabled...
if (!paganation){
$('.dataTables_info').css( 'display', 'none' );
}
});
}
javascript jquery css html5 datatables
|
show 11 more comments
I have a table with cells that contain list elements, the problem is that when I print the table I lose the list elements and the text becomes very hard to read. see the images.
here is my js to create a datatable, you can just focus on the buttons part.
$(document).ajaxSuccess(function() {
qxGenerateDataTables();
});
function qxGenerateDataTables() {
$("table.dataTable:not(table.dataTableProcessed)").each(function() {
var $this = $(this);
var paganation = !$this.hasClass("no-pagination");
var title = $this.attr ("data-file-name");
var excel= !$this.hasClass("no-excel");
var table = $this.DataTable({
"bPaginate": paganation,
"bSort": true,
stateSave: true,
ordering : true,
searching: true,
fixedHeader: true,
columnDefs : [ {
orderable : false,
targets : "no-sort"
} ]
,
dom:'B<"wrapper"iftlp>',
buttons: [
{
extend: 'excelHtml5',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa-file-excel-o fa-2x"></i>',
titleAttr: 'Excel',
title: title,
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr( 's', '55' );
}
},
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>'
}
]
});
table.buttons().container().appendTo( '#qxDatatable_wrapper .col-sm-6:eq(0)' );
//Surround the table with an outer div, to have the horizontal scroll working properly.
var wrapperDiv = $("<div>", {style:"overflow:auto; width: 100%;"});
$this.before(wrapperDiv);
wrapperDiv.append($this);
//Mark this table as processed.
$this.addClass('dataTableProcessed');
//Just hide the button for now until we find a better way.
if (!excel){
$('.fa-file-excel-o').css( 'display', 'none' );
}
//Hide the table info if pagination is disabled...
if (!paganation){
$('.dataTables_info').css( 'display', 'none' );
}
});
}
javascript jquery css html5 datatables
Your code seems OK. If you can give us a complete working jsfiddle, it will help us understand the possible css conflicts for instance...
– Pierre
Dec 31 '18 at 23:33
Ok let me prepare it
– QuakeCore
Dec 31 '18 at 23:34
@Pierre jsfiddle.net/quakecore/ws40x8oq/5 and I can't show the print button there for some reason can you help?
– QuakeCore
Dec 31 '18 at 23:54
is missing the 2 js for the buttons : cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js and the css cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css i suppose
– Pierre
Dec 31 '18 at 23:58
No I am sure I added them, and here is another try
– QuakeCore
Jan 1 at 0:15
|
show 11 more comments
I have a table with cells that contain list elements, the problem is that when I print the table I lose the list elements and the text becomes very hard to read. see the images.
here is my js to create a datatable, you can just focus on the buttons part.
$(document).ajaxSuccess(function() {
qxGenerateDataTables();
});
function qxGenerateDataTables() {
$("table.dataTable:not(table.dataTableProcessed)").each(function() {
var $this = $(this);
var paganation = !$this.hasClass("no-pagination");
var title = $this.attr ("data-file-name");
var excel= !$this.hasClass("no-excel");
var table = $this.DataTable({
"bPaginate": paganation,
"bSort": true,
stateSave: true,
ordering : true,
searching: true,
fixedHeader: true,
columnDefs : [ {
orderable : false,
targets : "no-sort"
} ]
,
dom:'B<"wrapper"iftlp>',
buttons: [
{
extend: 'excelHtml5',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa-file-excel-o fa-2x"></i>',
titleAttr: 'Excel',
title: title,
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr( 's', '55' );
}
},
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>'
}
]
});
table.buttons().container().appendTo( '#qxDatatable_wrapper .col-sm-6:eq(0)' );
//Surround the table with an outer div, to have the horizontal scroll working properly.
var wrapperDiv = $("<div>", {style:"overflow:auto; width: 100%;"});
$this.before(wrapperDiv);
wrapperDiv.append($this);
//Mark this table as processed.
$this.addClass('dataTableProcessed');
//Just hide the button for now until we find a better way.
if (!excel){
$('.fa-file-excel-o').css( 'display', 'none' );
}
//Hide the table info if pagination is disabled...
if (!paganation){
$('.dataTables_info').css( 'display', 'none' );
}
});
}
javascript jquery css html5 datatables
I have a table with cells that contain list elements, the problem is that when I print the table I lose the list elements and the text becomes very hard to read. see the images.
here is my js to create a datatable, you can just focus on the buttons part.
$(document).ajaxSuccess(function() {
qxGenerateDataTables();
});
function qxGenerateDataTables() {
$("table.dataTable:not(table.dataTableProcessed)").each(function() {
var $this = $(this);
var paganation = !$this.hasClass("no-pagination");
var title = $this.attr ("data-file-name");
var excel= !$this.hasClass("no-excel");
var table = $this.DataTable({
"bPaginate": paganation,
"bSort": true,
stateSave: true,
ordering : true,
searching: true,
fixedHeader: true,
columnDefs : [ {
orderable : false,
targets : "no-sort"
} ]
,
dom:'B<"wrapper"iftlp>',
buttons: [
{
extend: 'excelHtml5',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa-file-excel-o fa-2x"></i>',
titleAttr: 'Excel',
title: title,
customize: function( xlsx ) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row:first c', sheet).attr( 's', '55' );
}
},
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>'
}
]
});
table.buttons().container().appendTo( '#qxDatatable_wrapper .col-sm-6:eq(0)' );
//Surround the table with an outer div, to have the horizontal scroll working properly.
var wrapperDiv = $("<div>", {style:"overflow:auto; width: 100%;"});
$this.before(wrapperDiv);
wrapperDiv.append($this);
//Mark this table as processed.
$this.addClass('dataTableProcessed');
//Just hide the button for now until we find a better way.
if (!excel){
$('.fa-file-excel-o').css( 'display', 'none' );
}
//Hide the table info if pagination is disabled...
if (!paganation){
$('.dataTables_info').css( 'display', 'none' );
}
});
}
javascript jquery css html5 datatables
javascript jquery css html5 datatables
edited Dec 31 '18 at 23:25
QuakeCore
asked Dec 31 '18 at 23:19
QuakeCoreQuakeCore
1,4222926
1,4222926
Your code seems OK. If you can give us a complete working jsfiddle, it will help us understand the possible css conflicts for instance...
– Pierre
Dec 31 '18 at 23:33
Ok let me prepare it
– QuakeCore
Dec 31 '18 at 23:34
@Pierre jsfiddle.net/quakecore/ws40x8oq/5 and I can't show the print button there for some reason can you help?
– QuakeCore
Dec 31 '18 at 23:54
is missing the 2 js for the buttons : cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js and the css cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css i suppose
– Pierre
Dec 31 '18 at 23:58
No I am sure I added them, and here is another try
– QuakeCore
Jan 1 at 0:15
|
show 11 more comments
Your code seems OK. If you can give us a complete working jsfiddle, it will help us understand the possible css conflicts for instance...
– Pierre
Dec 31 '18 at 23:33
Ok let me prepare it
– QuakeCore
Dec 31 '18 at 23:34
@Pierre jsfiddle.net/quakecore/ws40x8oq/5 and I can't show the print button there for some reason can you help?
– QuakeCore
Dec 31 '18 at 23:54
is missing the 2 js for the buttons : cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js and the css cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css i suppose
– Pierre
Dec 31 '18 at 23:58
No I am sure I added them, and here is another try
– QuakeCore
Jan 1 at 0:15
Your code seems OK. If you can give us a complete working jsfiddle, it will help us understand the possible css conflicts for instance...
– Pierre
Dec 31 '18 at 23:33
Your code seems OK. If you can give us a complete working jsfiddle, it will help us understand the possible css conflicts for instance...
– Pierre
Dec 31 '18 at 23:33
Ok let me prepare it
– QuakeCore
Dec 31 '18 at 23:34
Ok let me prepare it
– QuakeCore
Dec 31 '18 at 23:34
@Pierre jsfiddle.net/quakecore/ws40x8oq/5 and I can't show the print button there for some reason can you help?
– QuakeCore
Dec 31 '18 at 23:54
@Pierre jsfiddle.net/quakecore/ws40x8oq/5 and I can't show the print button there for some reason can you help?
– QuakeCore
Dec 31 '18 at 23:54
is missing the 2 js for the buttons : cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js and the css cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css i suppose
– Pierre
Dec 31 '18 at 23:58
is missing the 2 js for the buttons : cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js and the css cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css i suppose
– Pierre
Dec 31 '18 at 23:58
No I am sure I added them, and here is another try
– QuakeCore
Jan 1 at 0:15
No I am sure I added them, and here is another try
– QuakeCore
Jan 1 at 0:15
|
show 11 more comments
2 Answers
2
active
oldest
votes
As Datatable code seems to remove the HTML code when printing, the solution is to remove your html tags (ie <li>
) by [li] and [/li]
Then :
you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file
instead of displaying
<li>
and</li>
, you display [li] and [/li] ...like this Datatable won't remove thisin your print.js code you change the line
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
by
dataOut = dataOut.replace("[li]","<li>");
dataOut = dataOut.replace("[/li]","</li>");
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
- you have finally to add a custom renderer in your cells for replacing [li] and [/li] by
<li>
and</li>
And it's done ! ;-)
And happy new year (near to 2h AM in France ;-) ) !!
will give it a try tomorrw :)
– QuakeCore
Jan 1 at 0:53
Good night! :-)
– Pierre
Jan 1 at 0:54
add a comment |
Turns out that all that was needed to be done is to turn off the scriptHtml
in the export options. Figured it out after looking at how the script works
Now my export button JS looks like this:
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>',
exportOptions:
{
stripHtml: false
}
}
Hi, good to know ! Thanks for the feedback !
– Pierre
Jan 1 at 13:32
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992087%2fdatatables-print-not-presenting-list-elements-properly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As Datatable code seems to remove the HTML code when printing, the solution is to remove your html tags (ie <li>
) by [li] and [/li]
Then :
you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file
instead of displaying
<li>
and</li>
, you display [li] and [/li] ...like this Datatable won't remove thisin your print.js code you change the line
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
by
dataOut = dataOut.replace("[li]","<li>");
dataOut = dataOut.replace("[/li]","</li>");
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
- you have finally to add a custom renderer in your cells for replacing [li] and [/li] by
<li>
and</li>
And it's done ! ;-)
And happy new year (near to 2h AM in France ;-) ) !!
will give it a try tomorrw :)
– QuakeCore
Jan 1 at 0:53
Good night! :-)
– Pierre
Jan 1 at 0:54
add a comment |
As Datatable code seems to remove the HTML code when printing, the solution is to remove your html tags (ie <li>
) by [li] and [/li]
Then :
you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file
instead of displaying
<li>
and</li>
, you display [li] and [/li] ...like this Datatable won't remove thisin your print.js code you change the line
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
by
dataOut = dataOut.replace("[li]","<li>");
dataOut = dataOut.replace("[/li]","</li>");
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
- you have finally to add a custom renderer in your cells for replacing [li] and [/li] by
<li>
and</li>
And it's done ! ;-)
And happy new year (near to 2h AM in France ;-) ) !!
will give it a try tomorrw :)
– QuakeCore
Jan 1 at 0:53
Good night! :-)
– Pierre
Jan 1 at 0:54
add a comment |
As Datatable code seems to remove the HTML code when printing, the solution is to remove your html tags (ie <li>
) by [li] and [/li]
Then :
you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file
instead of displaying
<li>
and</li>
, you display [li] and [/li] ...like this Datatable won't remove thisin your print.js code you change the line
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
by
dataOut = dataOut.replace("[li]","<li>");
dataOut = dataOut.replace("[/li]","</li>");
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
- you have finally to add a custom renderer in your cells for replacing [li] and [/li] by
<li>
and</li>
And it's done ! ;-)
And happy new year (near to 2h AM in France ;-) ) !!
As Datatable code seems to remove the HTML code when printing, the solution is to remove your html tags (ie <li>
) by [li] and [/li]
Then :
you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file
instead of displaying
<li>
and</li>
, you display [li] and [/li] ...like this Datatable won't remove thisin your print.js code you change the line
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
by
dataOut = dataOut.replace("[li]","<li>");
dataOut = dataOut.replace("[/li]","</li>");
str += '<'+tag+' '+classAttr+'>'+dataOut+'</'+tag+'>';
- you have finally to add a custom renderer in your cells for replacing [li] and [/li] by
<li>
and</li>
And it's done ! ;-)
And happy new year (near to 2h AM in France ;-) ) !!
answered Jan 1 at 0:48
PierrePierre
7329
7329
will give it a try tomorrw :)
– QuakeCore
Jan 1 at 0:53
Good night! :-)
– Pierre
Jan 1 at 0:54
add a comment |
will give it a try tomorrw :)
– QuakeCore
Jan 1 at 0:53
Good night! :-)
– Pierre
Jan 1 at 0:54
will give it a try tomorrw :)
– QuakeCore
Jan 1 at 0:53
will give it a try tomorrw :)
– QuakeCore
Jan 1 at 0:53
Good night! :-)
– Pierre
Jan 1 at 0:54
Good night! :-)
– Pierre
Jan 1 at 0:54
add a comment |
Turns out that all that was needed to be done is to turn off the scriptHtml
in the export options. Figured it out after looking at how the script works
Now my export button JS looks like this:
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>',
exportOptions:
{
stripHtml: false
}
}
Hi, good to know ! Thanks for the feedback !
– Pierre
Jan 1 at 13:32
add a comment |
Turns out that all that was needed to be done is to turn off the scriptHtml
in the export options. Figured it out after looking at how the script works
Now my export button JS looks like this:
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>',
exportOptions:
{
stripHtml: false
}
}
Hi, good to know ! Thanks for the feedback !
– Pierre
Jan 1 at 13:32
add a comment |
Turns out that all that was needed to be done is to turn off the scriptHtml
in the export options. Figured it out after looking at how the script works
Now my export button JS looks like this:
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>',
exportOptions:
{
stripHtml: false
}
}
Turns out that all that was needed to be done is to turn off the scriptHtml
in the export options. Figured it out after looking at how the script works
Now my export button JS looks like this:
{
extend: 'print',
text: '<i style="font-size:24px;color:#337ab7" class="fa fa fa-print fa-2x"></i>',
exportOptions:
{
stripHtml: false
}
}
answered Jan 1 at 12:36
QuakeCoreQuakeCore
1,4222926
1,4222926
Hi, good to know ! Thanks for the feedback !
– Pierre
Jan 1 at 13:32
add a comment |
Hi, good to know ! Thanks for the feedback !
– Pierre
Jan 1 at 13:32
Hi, good to know ! Thanks for the feedback !
– Pierre
Jan 1 at 13:32
Hi, good to know ! Thanks for the feedback !
– Pierre
Jan 1 at 13:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992087%2fdatatables-print-not-presenting-list-elements-properly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your code seems OK. If you can give us a complete working jsfiddle, it will help us understand the possible css conflicts for instance...
– Pierre
Dec 31 '18 at 23:33
Ok let me prepare it
– QuakeCore
Dec 31 '18 at 23:34
@Pierre jsfiddle.net/quakecore/ws40x8oq/5 and I can't show the print button there for some reason can you help?
– QuakeCore
Dec 31 '18 at 23:54
is missing the 2 js for the buttons : cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js and the css cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css i suppose
– Pierre
Dec 31 '18 at 23:58
No I am sure I added them, and here is another try
– QuakeCore
Jan 1 at 0:15