-1

I have one column in my table called "Info" where i have a code to render that column where if string is longer then 20 characters it will shorten it and put '...' at the end of string. Here is an example:

{
    targets: 4,
    "data": "info",
    "render": function(data, type, row, meta) {
        if(type === 'export') {
            return data;
        }
        if (data != null) {
            return type === 'display' && data.length > 20 ?
                '<p data-toggle="tooltip" title="' + data + '">' + data.substr(0, 20) + '...</p>' : data;
        } else {
            return data;
        }
    }
 },

Problem here is when I generate PDF I have data in that column shorten with '...', is it possible to have full data (full string) in pdf, excel etc. while having it shorten in table (column). I can always make one more column and make it invisible and then put that column in pdf. Is there any other way?

Nemanja
  • 119
  • 1
  • 3
  • 16

1 Answers1

1

In your render function, your correctly looking to see if the type is export:

if(type === 'export') {
    return data;
}

However, the type isn't export by default, even for PDFs or excels. You need to add the variable orthogonal to the export button decalaration object. This is then passed on to the render function as type

buttons: [
  {
    extend: 'excel',
    exportOptions: { orthogonal: 'export' }
  },
  {
    extend: 'pdf',
    exportOptions: { orthogonal: 'export' }
  }
]

More info on orthogonal here: https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html

lofihelsinki
  • 2,491
  • 2
  • 23
  • 35