Export CSV file with Chinese language content turn to be garbled
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
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 / downloadCSV and 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!
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/downloadCSVandexporterthing 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.
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/downloadCSVandexporterthing 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