Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data-export attribute #314

Open
petermorlion opened this issue Jan 31, 2025 · 3 comments
Open

Add data-export attribute #314

petermorlion opened this issue Jan 31, 2025 · 3 comments

Comments

@petermorlion
Copy link

Datatables currently supports 4 data-* attributes in the HTML. In this thread you thought about creating a fifth, data-export. Is this still something on your mind? I'm willing to help, because I could use this feature.

Basically, I have quite some tables to show, and always the same way. I'm using PHP to already render my tables and then applying Datatables to it. In these tables, I often have decimal numbers. In Belgium, I want to show them with a comma (for example 98522,42). But I export it to Excel, the numbers are changed (for example to 9852.242. This might of course be an Excel thing, but I doubt my customers will be happy with that explanation :) I could easily fix it if I can display the numbers with a comma (e.g. 98522,42) and export with a dot (e.g. 98522.42).

@AllanJard
Copy link
Contributor

With the raw format that Excel uses, the decimal character is a dot. If you want to see it as a number, you need to store it as such. A comma decimal would be seen as a string.

What you need to do is instruct Excel to display the number in a locale specific way. I actually don't know how to do that I'm afraid. The way I normally look into the Excel format is to create a worksheet that I want, rename the .xlsx file to .zip, unzip and explore the contents.

I don't believe that data-export would help in this case I'm afraid. However, it should be noted that Button's export does support orthogonal data and columns.data can be configured to use data-export. It isn't what you want I'd say though - the Excel file must be created with a dot decimal.

@petermorlion
Copy link
Author

Couldn't data-export help if that's what was sent to Excel? Now it's using the display value for Excel. If we can make it use something else, that would work for me (because if I change the display value, Excel shows it correctly).

@AllanJard
Copy link
Contributor

You can indeed make it use something else, using the orthogonal option mentioned in the example I linked to.

Alternatively, if you were Ajax load your data, then you could use the built in number rendering helper which will format the number suitable for the user's locale settings, without you needing to change the data. Then the export data will be the original number, and it is up to Excel to format it appropriately for the locale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants