Search code examples
javascriptjqueryhtmldatatablespdfmake

<br/> tag in HTML title breaks pdfmake export in jQuery DataTables


I am trying to format how the data is displayed in a jquery DataTable.

If the text is long, I truncate it like below:

{
"data": "col1", "render": function (data, type, row) {
        if (type === 'display' && data != null) {
              data = data.replace(/<(?:.|\\n)*?>/gm, '');
              data = data.split("; ").join("<br/>");
                  if (data.length > 85) {

                      return '<span class=\"show-ellipsis\" title="'+data+'">' + data.substr(0, 85) + '</span><span class=\"no-show\">' + data.substr(85) + '</span>';
                  } else {
                      return data;
                  }
        } else {
           return data;
        }
   }
},

and use the following CSS alongside jquery UI tooltip.

CSS

 span.no-show {
    display: none;
}

span.show-ellipsis:after {
    content: "...";
}

jQuery UI tooltip

<script>
$(function () {
    $(document).tooltip({
        items: 'span.show-ellipsis',
        content: function () {
            return $(this).attr('title');
        },
        position: {
            my: "center bottom",
            at: "center top-10",
            collision: "flip",
            using: function (position, feedback) {
                $(this).addClass(feedback.vertical)
                    .css(position);
            }
        }

    });

});


This way it appears nicely in the DataTable,

datatable

The screenshot above had <hr> instead of <br/> tag in replace method, but the behavior remains the same. It works fine if I replace with \n. When I try to export the pdf, data gets repeated. In particular the data.substr(85) part.

pdf export

What am I doing wrong?

Thank you


Solution

  • ok, in your button

                    extend: 'pdfHtml5',
                    exportOptions: {
                        orthogonal: 'export',
                    }
    

    in your columns :

            render: function (data, type, row) {
            return type === 'export' ? row.Descripcion: "";
         }