有人知道如何在材料表(材料UI)中进行日期选择器的本地化吗?在此示例中,过滤时使用日期选择器。
import React from 'react';
import MaterialTable from 'material-table';
function App() {
return (
<MaterialTable
title="Simple Action Preview"
columns={[
{ title: 'Birthday', field: 'birthDay', type: 'date'},
]}
data={[
{ birthDay: "08-30-2020" },
]}
options={{
filtering: true
}}
/>
);
}
export default App;
答案 0 :(得分:1)
localization的材料UI文档
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
import { zhCN } from '@material-ui/core/locale';
const theme = createMuiTheme({
palette: {
primary: { main: '#1976d2' },
},
}, zhCN);
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
答案 1 :(得分:1)
在各列中添加dateSetting。
const columns = [
{
title: "Simple Action Preview",
field: 'birthYear',
type: "date",
dateSetting: { locale: "ko-KR"}
....
}
]
答案 2 :(得分:0)
npx create-react-app datepicker
cd .\datepicker\
npm install material-table @material-ui/core --save
文件App.js
import React from 'react';
import MaterialTable from 'material-table';
import ruLocale from 'date-fns/locale/ru';
function App() {
return (
<MaterialTable
title="Simple Action Preview"
columns={[
{ title: 'Birthday', field: 'birthDay', type: 'date'},
]}
data={[
{ birthDay: "08-30-2020" },
]}
options={{
filtering: true
}}
localization={{
body: {
dateTimePickerLocalization: ruLocale
}
}}
/>
);
}
export default App;