CSVHtml5 buttons fails when data is from JSON and some columns are not string.

CSVHtml5 buttons fails when data is from JSON and some columns are not string.

jorge33jorge33 Posts: 1Questions: 0Answers: 0
edited November 2015 in Free community support

Source code: https://cdn.datatables.net/buttons/1.0.2/js/buttons.html5.js

I was debugging and in the line 305 of previous link.

    for ( var i=0, ien=a.length ; i<ien ; i++ ) {
        if ( i > 0 ) {
            s += separator;
        }

        s += boundary ?
            boundary + a[i].replace( boundary, '\\'+boundary ) + boundary :
            a[i];
    }

The a[i] is a field value from JSON data in datatable, So, when the a[i] is not a String, (For example a number), I get an error because a number doesnt have .replace function.

A simple fix could be to replace "a[i].replace" to "a[i].toString().replace" .

In my case, I just added and works.

Replies

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Please update to the current 1.1.0 release which addresses this issue.

    Allan

This discussion has been closed.