antd通过 filterDropdown 自定义按某天时间搜索功能
作者:别样青春 时间:2023-08-25 07:57:05
import React, { Component } from 'react';
import { Table, Input, Button, Icon, DatePicker } from 'antd';
import moment from 'moment';
import Highlighter from 'react-highlight-words';
export default class RpoliceRecord extends Component {
constructor(props) {
super(props);
this.state = {
searchText: '',
}
}
render() {
// 添加搜索
this.getColumnSearchProps = (dataIndex, title) => ({
filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
<div style={{ padding: 8 }}>
<Input
ref={node => {
this.searchInput = node;
}}
placeholder={`搜索 ${title}`}
value={selectedKeys[0]}
onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
onPressEnter={() => this.handleSearch(selectedKeys, confirm)}
style={{ width: 188, marginBottom: 8, display: 'block' }}
/>
<Button
type="primary"
onClick={() => this.handleSearch(selectedKeys, confirm)}
icon="search"
size="small"
style={{ width: 90, marginRight: 8 }}>
搜索
</Button>
<Button onClick={() => this.handleReset(clearFilters)} size="small" style={{ width: 90 }}>重置</Button>
</div>
),
filterIcon: filtered => (
<Icon type="search" style={{ color: filtered ? '#1890ff' : undefined }} />
),
onFilter: (value, record) =>
record[dataIndex]
.toString()
.toLowerCase()
.includes(value.toLowerCase()),
onFilterDropdownVisibleChange: visible => {
if (visible) {
setTimeout(() => this.searchInput.select());
}
},
render: text => (
<Highlighter
highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
searchWords={[this.state.searchText]}
autoEscape
textToHighlight={text.toString()}
/>
),
});
//搜索
this.handleSearch = (selectedKeys, confirm) => {
confirm();
console.log(selectedKeys,confirm);
this.setState({ searchText: selectedKeys[0] });
};
this.handleSearchtime = (selectedKeys, confirm) => {
confirm();
this.setState({ searchText: selectedKeys });
};
//重置
this.handleReset = clearFilters => {
clearFilters();
this.setState({ searchText: '' });
};
const columns = [
{ title: '报警时间', dataIndex: 'time', key: 'time',
filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
<div style={{ padding: 8 }}>
<DatePicker placeholder={`搜索时间`}
value={selectedKeys[0]}
onChange={dateString => setSelectedKeys(dateString ? [dateString] : [])}
onPressEnter={() => this.handleSearch(selectedKeys, confirm)}
style={{ width: 188, marginBottom: 8, display: 'block' }}/>
<Button
type="primary"
onClick={() => this.handleSearchtime(moment(selectedKeys[0]._d).format('YYYY-MM-DD'), confirm)}
icon="search"
size="small"
style={{ width: 90, marginRight: 8 }}>
搜索
</Button>
<Button onClick={() => this.handleReset(clearFilters)} size="small" style={{ width: 90 }}>重置</Button>
</div>
),
filterIcon: filtered => (
<Icon type="search" style={{ color: filtered ? '#1890ff' : undefined }} />
),
onFilter: (value, record) => {
return record.time.indexOf(moment(value).format('YYYY-MM-DD')) != -1},
render: text => (
<Highlighter
highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
searchWords={[this.state.searchText]}
autoEscape
textToHighlight={text.toString()}
/>
),
},
{ title: '来电', key: 'callnum', dataIndex: 'callnum', ...this.getColumnSearchProps('callnum', '来电'), },
{ title: '时长', key: 'longtime', dataIndex: 'longtime', }
];
const data = [
{ key: '1', time: '2019-07-30 16:31:05', callnum: '13546540218', longtime: '37秒' },
{ key: '2', time: '2019-06-24 22:08:05', callnum: '13546540218', longtime: '1分12秒' },
{ key: '3', time: '2017-08-15 12:31:05', callnum: '13546540218', longtime: '1分10秒' },
{ key: '4', time: '2016-12-30 06:15:00', callnum: '13546540218', longtime: '20秒' }
];
return (
<Table className="accidentTable" columns={columns} dataSource={data} bordered size="small" />
)
}
}
总结
以上所述是小编给大家介绍的antd通过 filterDropdown 自定义按某天时间搜索功能,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://www.cnblogs.com/takenotes-MUZI/p/11337926.html
标签:antd,filterDropdown,时间,搜索
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
torch.optim优化算法理解之optim.Adam()解读
2023-06-24 23:30:25
![](https://img.aspxhome.com/file/2023/9/72739_0s.png)
Python全栈之队列详解
2022-10-12 07:51:33
![](https://img.aspxhome.com/file/2023/5/85385_0s.png)
Python tempfile模块生成临时文件和临时目录
2022-06-28 05:20:20
Python 调用VC++的动态链接库(DLL)
2023-06-19 09:01:44
Python和Bash结合在一起的方法
2023-11-02 20:53:27
以独占方式打开Access数据库
2007-10-22 12:24:00
php打包压缩文件之ZipArchive方法用法分析
2024-05-11 09:46:05
Python数据类型转换详解
2021-03-04 04:11:13
MySQL 主从同步,事务回滚的实现原理
2024-01-17 14:16:51
使用OpenCV实现仿射变换—平移功能
2022-11-01 01:45:06
![](https://img.aspxhome.com/file/2023/2/103172_0s.jpg)
python 如何去除字符串头尾的多余符号
2021-12-29 03:17:36
解决pycharm 格式报错tabs和space不一致问题
2022-10-12 11:36:12
![](https://img.aspxhome.com/file/2023/7/128737_0s.jpg)
深入浅析ImageMagick命令执行漏洞
2022-07-21 11:50:46
![](https://img.aspxhome.com/file/2023/0/70870_0s.png)
使用ASP订制自己的XML文件读写方法
2008-10-24 09:35:00
Python 格式化输出_String Formatting_控制小数点位数的实例详解
2023-11-29 12:09:14
Python爬虫获取基金净值信息详情
2022-04-23 07:53:42
![](https://img.aspxhome.com/file/2023/3/127013_0s.webp)
一文彻底理清session、cookie、token的区别
2024-01-02 06:16:29
![](https://img.aspxhome.com/file/2023/6/132376_0s.jpg)
利用pandas按日期做分组运算的操作
2021-03-06 09:16:17
CSS Sprites 样式生成工具 2.0下载
2009-05-13 12:41:00
![](https://img.aspxhome.com/file/UploadPic/20095/13/20090512-pia7mda76k6mx2nwf2s3nx54tc-19s.jpg)
不成熟的标准化是我们唯一惧怕的
2008-08-15 18:55:00