react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Export CSV file with Chinese language content turn to be garbled

Open samz-github opened this issue 7 years ago • 12 comments

What you were expecting:

Export CSV file with Chinese language content shoule be work well. What happened instead:

Export CSV file with Chinese language content turn to be garbled.

Environment

  • React-admin version: 2.9.6
  • React version: 16.3.1
  • Browser: Firefox/Chrome

samz-github avatar Sep 14 '19 14:09 samz-github

The core team has no Chinese speaker, nor do we have any way of producing Chinese content. Please follow the issue template and provide a link to a CodeSandbox reproducing the issue.

fzaninotto avatar Sep 16 '19 16:09 fzaninotto

Thanks @fzaninotto for your attention. As your advice, I have created a link: https://2is57.csb.app/#/users on CodeSandbox to reproduce this issue. As you can see, once you create EXPORT button, the CSV file will be download. But the chinese character turn to be garbled, like '?????'...The English character is fine. Source code: https://codesandbox.io/s/react-admin-advanced-recipes-create-a-record-related-to-the-current-one-2is57

samz-github avatar Sep 18 '19 13:09 samz-github

If it helps v3 alpha doesn't have this issue and many others I think its the parser.

MohammedFaragallah avatar Sep 21 '19 13:09 MohammedFaragallah

If it helps v3 alpha doesn't have this issue and many others I think its the parser.

@MohammedFaragallah , I have tried update the react admin version to 3.0.0-alpha.3. But happen error, see https://2is57.csb.app/...

samz-github avatar Sep 25 '19 09:09 samz-github

@samz-github You should follow this UPGRADE guide but from the stack trace, I think you didn't update react version

MohammedFaragallah avatar Sep 25 '19 13:09 MohammedFaragallah

@MohammedFaragallah , I have followed UPGRADE guide to upgrade, but happen another error:

Could not fetch dependencies, please try again in a couple seconds: Could not fetch version for react-admin@^3.0.0: No matching version found for react-admin@^3.0.0

samz-github avatar Sep 29 '19 01:09 samz-github

@samz-github react-admin@^3.0.0 is not released, but pre-release exist, see here

kopax avatar Sep 29 '19 02:09 kopax

@kopax , gotcha, I updated it to react-admin@^3.0.0-alpha.3. And error is gone. But the export CSV file with chinese character still do not work.

samz-github avatar Sep 29 '19 02:09 samz-github

Hello,

Here is my take on this bug, at least for react-admin 2.9 :

const exporter = data => {
    const csv = convertToCSV({data})
    const BOM = '\uFEFF'
    downloadCSV(`${BOM} ${csv}`, 'export')
}

This bug is due to the lack of BOM at the start of the file, so we just need to add it before the download occurs.

More information about the convertToCSV / downloadCSV and exporter thing can be found in the documentation : https://marmelab.com/react-admin/doc/2.9/List.html#exporter

boutdemousse avatar Feb 10 '20 06:02 boutdemousse

Awesome, it works! Thanks @boutdemousse great!

samz-github avatar Mar 18 '20 07:03 samz-github

Hello,

Here is my take on this bug, at least for react-admin 2.9 :

const exporter = data => {
    const csv = convertToCSV({data})
    const BOM = '\uFEFF'
    downloadCSV(`${BOM} ${csv}`, 'export')
}

This bug is due to the lack of BOM at the start of the file, so we just need to add it before the download occurs.

More information about the convertToCSV / downloadCSV and exporter thing can be found in the documentation : https://marmelab.com/react-admin/doc/2.9/List.html#exporter

I wonder if this could be the default behavior.

adonese avatar Jul 31 '21 11:07 adonese

Hello,

Here is my take on this bug, at least for react-admin 2.9 :

const exporter = data => {
    const csv = convertToCSV({data})
    const BOM = '\uFEFF'
    downloadCSV(`${BOM} ${csv}`, 'export')
}

This bug is due to the lack of BOM at the start of the file, so we just need to add it before the download occurs.

More information about the convertToCSV / downloadCSV and exporter thing can be found in the documentation : https://marmelab.com/react-admin/doc/2.9/List.html#exporter

Thank you very much!! I think without this answer I wouldn't have been able to solve this issue, at least not so fast. With the latest version the code needs to be changed a little bit:

import { List, downloadCSV } from 'react-admin';
import jsonExport from 'jsonexport/dist';

const exporter = (data) => {
  const BOM = '\uFEFF'

  jsonExport(data, (err, csv) => {
    downloadCSV(`${BOM} ${csv}`, 'templates')
    if (err) {
      console.log('Error trying to export list')
    }
  })
}

Official doc: https://marmelab.com/react-admin/List.html#exporter

PRossetti avatar Sep 04 '21 23:09 PRossetti