React-admin: Export CSV file with Chinese language content turn to be garbled

Created on 14 Sep 2019  路  10Comments  路  Source: marmelab/react-admin

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
bug good first issue

Most helpful comment

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.

All 10 comments

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.

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

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

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 You should follow this UPGRADE guide
but from the stack trace, I think you didn't update react version

@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 react-admin@^3.0.0 is not released, but pre-release exist, see here

@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.

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 / downloadCSVand exporter thing can be found in the documentation : https://marmelab.com/react-admin/doc/2.9/List.html#exporter

Awesome, it works! Thanks @boutdemousse great!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicgirault picture nicgirault  路  3Comments

yangjiamu picture yangjiamu  路  3Comments

kopax picture kopax  路  3Comments

Dragomir-Ivanov picture Dragomir-Ivanov  路  3Comments

phacks picture phacks  路  3Comments