How to use localization in React DataTable
How to use localization in React DataTable
in DataTables
I have been using DataTable frequently in JS applications, but right now is the first time to use it as part of a React application. I created a translation object like this:
const tableTranslations = {
"emptyTable": I18N`No data available`,
"info": I18N`Showing _START_ to _END_ of _TOTAL_ entries`,
"infoEmpty": I18N`Showing 0 to 0 of 0 entries`,
...
}
But I haven't found a way to pass it into the data table, e.g., this won't work:
<DataTable columns={communicationColumns} data={systemIssues} localization={tableTranslations}
pagination/>
I had a look at the documentation, but couldn't find an example of internationalization in React.
Thanks for your help in advance!
This question has an accepted answers - jump to answer
Answers
Hi,
There isn't a
localizationparameter for the<DataTable>component, which is why the above won't do anything (in fact, it should show an error in Typescript).Instead, what to do is use the
optionsparameter which allows you to pass in any of the DataTables options. For example:I tried making a StackBlitz showing that but it is failing to install in their IDE at the moment. Downloading the project will allow it to work if you want to see that example running.
The
<DataTables>component and the parameters it accepts is documented here.Allan
Hi Allan,
Thanks for the explanation. I just realized I had used a different component - react-data-table-component -, which is in parts similar to DataTables. I just found the link to the reference documentation of said component and am now able to localize. Thank you for taking the time to read and answer!
Best regards, Sascha