2017-09-25 22:10:26 +08:00
|
|
|
---
|
|
|
|
order: 12
|
|
|
|
title:
|
2017-09-25 22:16:13 +08:00
|
|
|
zh-CN: 定制日期单元格
|
2017-09-25 22:10:26 +08:00
|
|
|
en-US: Customized Date Rendering
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2017-09-25 22:16:13 +08:00
|
|
|
使用 `dateRender` 可以自定义日期单元格的内容和样式。
|
2017-09-25 22:10:26 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
We can customize the rendering of date cells in the calendar by providing a `dateRender` function to `DatePicker`.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2020-07-30 19:17:34 +08:00
|
|
|
import { DatePicker, Space } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-09-25 22:10:26 +08:00
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
|
|
|
ReactDOM.render(
|
2020-07-30 19:17:34 +08:00
|
|
|
<Space direction="vertical" size={12}>
|
2017-09-25 22:10:26 +08:00
|
|
|
<DatePicker
|
2019-05-07 14:57:32 +08:00
|
|
|
dateRender={current => {
|
2017-09-25 22:10:26 +08:00
|
|
|
const style = {};
|
|
|
|
if (current.date() === 1) {
|
2017-10-11 12:01:27 +08:00
|
|
|
style.border = '1px solid #1890ff';
|
2017-09-25 22:10:26 +08:00
|
|
|
style.borderRadius = '50%';
|
|
|
|
}
|
|
|
|
return (
|
2020-02-25 19:41:43 +08:00
|
|
|
<div className="ant-picker-cell-inner" style={style}>
|
2017-09-25 22:10:26 +08:00
|
|
|
{current.date()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<RangePicker
|
2019-05-07 14:57:32 +08:00
|
|
|
dateRender={current => {
|
2017-09-25 22:10:26 +08:00
|
|
|
const style = {};
|
|
|
|
if (current.date() === 1) {
|
2017-10-11 12:01:27 +08:00
|
|
|
style.border = '1px solid #1890ff';
|
2017-09-25 22:10:26 +08:00
|
|
|
style.borderRadius = '50%';
|
|
|
|
}
|
|
|
|
return (
|
2020-02-25 19:41:43 +08:00
|
|
|
<div className="ant-picker-cell-inner" style={style}>
|
2017-09-25 22:10:26 +08:00
|
|
|
{current.date()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
2020-07-30 19:17:34 +08:00
|
|
|
</Space>,
|
2019-05-07 14:57:32 +08:00
|
|
|
mountNode,
|
2018-11-28 15:00:03 +08:00
|
|
|
);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|