Datatables export csv has unicode symbols pound symbol, how to get rid of this?

Datatables export csv has unicode symbols pound symbol, how to get rid of this?

mohan5070mohan5070 Posts: 12Questions: 2Answers: 1

When i try to export a csv file which has pound symbol in one particular column,, it will get appended with "£" this character..

Kindly guide me to get rid of this.

This question has an accepted answers - jump to answer

Answers

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1
    edited March 2017

    I want only pound symbol.. i tried export options to replace that extra character.. but it removed pound symbol as well..

    This is my code for removing extra character

     exportOptions: {
                    format: {
                        body: function ( data, row, column, node ) {
                            debugger;
                            if(column === 3) {
                                return node.innerHTML.replace(/[^a-zA-Z0-9_\.,\-_ !\(\)]/g, "");
                            }else {
                                return node.innerText;
                            }
                        }
                    }
                }
    

    Please help me to fix this

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Happy to take a look at a test case if you provide a link (per the forum rules).

    Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1
    edited March 2017

    Hi Allan,

    Thanks for quick reply. I have added my code here. https://jsfiddle.net/mohan5070/e6hhfx4h/

    Please have a look.. unfortuanately i am not able to show the csv button in jsfiddle.
    Kindly have a look at my code and if possible try csv export you will get to know what is the issue..

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    With the buttons in, it appears to work just fine for me: https://jsfiddle.net/e6hhfx4h/1/ .

    Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1

    With your changes.. i am still seeing the same error... Screenshot attached..
    I am using windows machine...

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    If you view the CSV file in a text Editor, what do you see?

    Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1
    edited March 2017

    When i open with text Editor "Notepad",, it coming like this:-
    "name","Amount"
    "abc","£159.5"
    "xyz","£159.5"

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Sounds like an Excel issue in that case :smile:. Opening it in LibreOffice and it works no problem.

    Does Excel have an open in UTF-8 option?

    Allan

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    I'd forgotten I have Excel in VM. Just tired it and right enough it mashes the UTF8 characters.

    You are far from the only one to have this issue with Excel - this SO thread among many others discusses it.

    So you need to jump through Excel hoops to have it read CSV as UTF-8. Or just export a Excel file from Buttons.

    Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1

    Sorry Allan.. I am still not clear what has to be done to resolve this extra characters

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Two options that I can see:

    1. Use the excelHtml5 button instead
    2. Use the instructions in the SO thread I linked to above inside Excel to import the CSV data.

    You will not be able to double click the CSV file and have Excel read it correctly. That is an Excel issue. Not one with the CSV file.

    Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1
    edited March 2017

    Hi Allan..

    I am using excel export. it opens up the file explorer to add filename for saving the excel file.. How can i get rid of this file explorer and directly download the excel file

    Thanks,
    mohan

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin
    Answer ✓

    If you are using the Flash button (excelFlash) there is no way to remove the save dialogue. That is part of the Flash run time and there is no option to avoid that.

    If you are using the HTML5 button (excelHtml5) then it is entirely dependent upon the browser settings. For example on Chrome Mac for me it will immediately download without a "save as" box.

    Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1

    Thanks Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1
    edited March 2017

    Hi Allan,,

    I tried using excel button for export.. but the button is not showing firefox..
    Could you tell me what could be the reason?

    I dont want to use flash installing process.. Is there any other native way of fixing this?

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Without a link to the page showing the issue I don't know what is causing that I'm afraid. As you'll be able to see in my examples, the Excel button should appear in Firefox.

    Allan

  • mohan5070mohan5070 Posts: 12Questions: 2Answers: 1

    I am not able reproduce the issue in Jsfiddle .. Same dependency files i am injecting in my backbone module.. but excel button not showing up in firefox.. if I install flash for firefox then it shows up...

    I am wondering how come this works fine in jsfiddle? not sure whether this jsFiddle has inbuilt Flash or not?

    these are the files i included in my module

    require('https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js');
    require('https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js');
    require('https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.min.css!');
    require('https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js');
    require('https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js');
    require('https://cdn.datatables.net/buttons/1.2.4/js/buttons.html5.min.js');
    require('https://cdn.datatables.net/buttons/1.2.4/js/buttons.flash.min.js');

    then i tried
    $('#example').DataTable( {
    "bProcessing" : true,
    dom: 'Bfrtip',
    buttons: [
    'excelHtml5'
    ],
    } );

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    not sure whether this jsFiddle has inbuilt Flash or not?

    No. Its the browser that would have Flash built in order, not a site.

    I don't see any issue with the above code, that looks like it should basically work. I'd really need a link to a page showing the issue to be able to offer any help. If it can't be reproduced on JSFiddle, then there must be something in your local page that is causing the problem. What it is - I have no idea :smile:.

    Allan

This discussion has been closed.