datatables print not presenting list elements properly












2















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.enter image description here



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' );
}

});
}









share|improve this question

























  • 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
















2















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.enter image description here



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' );
}

});
}









share|improve this question

























  • 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














2












2








2


1






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.enter image description here



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' );
}

});
}









share|improve this question
















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.enter image description here



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












2 Answers
2






active

oldest

votes


















2














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 :




  1. you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file


  2. instead of displaying <li> and </li>, you display [li] and [/li] ...like this Datatable won't remove this


  3. in 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+'>';




  1. 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 ;-) ) !!






share|improve this answer
























  • will give it a try tomorrw :)

    – QuakeCore
    Jan 1 at 0:53











  • Good night! :-)

    – Pierre
    Jan 1 at 0:54



















2














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
}
}





share|improve this answer
























  • Hi, good to know ! Thanks for the feedback !

    – Pierre
    Jan 1 at 13:32











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
});


}
});














draft saved

draft discarded


















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









2














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 :




  1. you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file


  2. instead of displaying <li> and </li>, you display [li] and [/li] ...like this Datatable won't remove this


  3. in 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+'>';




  1. 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 ;-) ) !!






share|improve this answer
























  • will give it a try tomorrw :)

    – QuakeCore
    Jan 1 at 0:53











  • Good night! :-)

    – Pierre
    Jan 1 at 0:54
















2














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 :




  1. you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file


  2. instead of displaying <li> and </li>, you display [li] and [/li] ...like this Datatable won't remove this


  3. in 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+'>';




  1. 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 ;-) ) !!






share|improve this answer
























  • will give it a try tomorrw :)

    – QuakeCore
    Jan 1 at 0:53











  • Good night! :-)

    – Pierre
    Jan 1 at 0:54














2












2








2







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 :




  1. you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file


  2. instead of displaying <li> and </li>, you display [li] and [/li] ...like this Datatable won't remove this


  3. in 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+'>';




  1. 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 ;-) ) !!






share|improve this answer













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 :




  1. you take https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.js and create your own print.js file


  2. instead of displaying <li> and </li>, you display [li] and [/li] ...like this Datatable won't remove this


  3. in 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+'>';




  1. 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 ;-) ) !!







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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













2














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
}
}





share|improve this answer
























  • Hi, good to know ! Thanks for the feedback !

    – Pierre
    Jan 1 at 13:32
















2














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
}
}





share|improve this answer
























  • Hi, good to know ! Thanks for the feedback !

    – Pierre
    Jan 1 at 13:32














2












2








2







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
}
}





share|improve this answer













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
}
}






share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas