Replies: 2 comments 3 replies
-
I think you are over thinking it. The locale can be passed in dynamicly in just about any way possible. Sure use context, or state, or whatever. |
Beta Was this translation helpful? Give feedback.
-
I like this idea. We are also having lot's of different tables and there are some boilerplate configuration that needs to be provider for each table instance. e.g. used locale, mrtTheme, default density state etc. Altough it's not difficult to create custom hook which extends export function useCustomMaterialReactTable<TData extends MRT_RowData>({
initialState,
...options
}: MRT_TableOptions<TData>) {
const { mrtLocale } = useLocale();
const tableInstance = useMaterialReactTable<TData>({
localization: mrtLocale,
mrtTheme: (theme) => ({
baseBackgroundColor: theme.palette.background.paper,
}),
initialState: {
density: 'compact',
...initialState,
},
...options,
});
return tableInstance;
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi and thank you first for this awesome library!
Currently we have to set the localization per table instance https://www.material-react-table.com/docs/guides/localization#relevant-table-options
I find it unlikely that an app mixes several languages in its UI, hence we would set the same locale in each of our table instances.
Similarly to theme or date localization adapter, I would expect having the ability to define the (default) locale once in the app, typically as a context provider, like theme. This would also prevent some future dev from forgetting to set the localization of a new table instance.
Of course, I could write a custom hook wrapper around
useMaterialReactTable
to set the locale, but again, some future dev might miss my custom hook and use the plainuseMaterialReactTable
hook directly instead, bypassing my "default" option setting.I tried deep mutating the
MRT_Localization_EN
object that is used as default value in MRT, but unfortunately the library build embeds it insideindex.esm.js
and does not export it; theMRT_Localization_EN
object that we can import from"material-react-table/locales/en"
is actually a different reference, therefore mutating it has no effect. If the former were exported, this hack could work.But beyond global localization, the same idea may apply to other default options, like
MRT_Default_Icons
(which is also not exported).Therefore I am posting this Feature Request: add the ability to define common MRT options, typically at app-level.
As for the implementation, we could imagine a Context that is consumed to set the default options, for example something like:
I can submit a Pull Request if you are ready to take such feature in.
Please let me know!
Beta Was this translation helpful? Give feedback.
All reactions