How to use "Ellipsis Renderer" for screen only, and not for export to excel

How to use "Ellipsis Renderer" for screen only, and not for export to excel

rdmrdm Posts: 194Questions: 55Answers: 4
edited October 2022 in DataTables 1.10

I found the ellipsis renderer for truncating long text. https://datatables.net/blog/2016-02-26 It works great, but the only downside is that it also truncates exported text. Is there a way to only truncate text on the screen, but not in export?

Here's what I'm using.

$(() => {
// This render function truncates anything more than 100 characters.
$.fn.dataTable.render.ellipsis = function () {
return function ( data, type, row ) {
return type === 'display' && data.length > 100 ?
data.substr( 0, 100 ) +'…' :
data;
}
};

        // Only column 11 uses the render function.
        $(".display").DataTable({
            dom: 'Blftipr',
            "sScrollX": true,
            paging: false,
            autoWidth: false,
            "bScrollCollapse": true,
            buttons: ['excelHtml5', 'print'],
            columnDefs: [ {                    
                targets: 11,
                render: $.fn.dataTable.render.ellipsis()
            } ]
        });
    });

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Looking at the renderer code the first thing it does is return the original data for all orthogonal data types except display. The Orthognal data export example explains that exporting uses the display data. Based on this I see tow options.

    One option is to use orthogonal data as shown in that example to export the original data. To do this you will need to modify the plugin code to first check to see if the type === "export" and return the original data.

    The second option is to format the out like this example and have it return the original cell data, something like this:
    http://live.datatables.net/dawoqewu/1/edit

    There maybe other options but those are the two I see.

    Kevin

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Between this thread and another recent one, I think there is a strong argument for changing the default orthogonal data export to be export...

    Allan

Sign In or Register to comment.