1. import React, { Component } from 'react';
  2. import { Table, Input, Button, Icon, DatePicker } from 'antd';
  3. import moment from 'moment';
  4. import Highlighter from 'react-highlight-words';
  5.  
  6. export default class RpoliceRecord extends Component {
  7.  
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. searchText: '',
  12. }
  13. }
  14.  
  15. render() {
  16. // 添加搜索
  17. this.getColumnSearchProps = (dataIndex, title) => ({
  18. filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
  19. <div style={{ padding: 8 }}>
  20. <Input
  21. ref={node => {
  22. this.searchInput = node;
  23. }}
  24. placeholder={`搜索 ${title}`}
  25. value={selectedKeys[0]}
  26. onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
  27. onPressEnter={() => this.handleSearch(selectedKeys, confirm)}
  28. style={{ width: 188, marginBottom: 8, display: 'block' }}
  29. />
  30. <Button
  31. type="primary"
  32. onClick={() => this.handleSearch(selectedKeys, confirm)}
  33. icon="search"
  34. size="small"
  35. style={{ width: 90, marginRight: 8 }}>
  36. 搜索
  37. </Button>
  38. <Button onClick={() => this.handleReset(clearFilters)} size="small" style={{ width: 90 }}>重置</Button>
  39. </div>
  40. ),
  41. filterIcon: filtered => (
  42. <Icon type="search" style={{ color: filtered ? '#1890ff' : undefined }} />
  43. ),
  44. onFilter: (value, record) =>
  45. record[dataIndex]
  46. .toString()
  47. .toLowerCase()
  48. .includes(value.toLowerCase()),
  49. onFilterDropdownVisibleChange: visible => {
  50. if (visible) {
  51. setTimeout(() => this.searchInput.select());
  52. }
  53. },
  54. render: text => (
  55. <Highlighter
  56. highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
  57. searchWords={[this.state.searchText]}
  58. autoEscape
  59. textToHighlight={text.toString()}
  60. />
  61. ),
  62. });
  63. //搜索
  64. this.handleSearch = (selectedKeys, confirm) => {
  65. confirm();
  66. console.log(selectedKeys,confirm);
  67. this.setState({ searchText: selectedKeys[0] });
  68. };
  69. this.handleSearchtime = (selectedKeys, confirm) => {
  70. confirm();
  71. this.setState({ searchText: selectedKeys });
  72. };
  73. //重置
  74. this.handleReset = clearFilters => {
  75. clearFilters();
  76. this.setState({ searchText: '' });
  77. };
  78. const columns = [
  79. { title: '报警时间', dataIndex: 'time', key: 'time',
  80. filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
  81. <div style={{ padding: 8 }}>
  82. <DatePicker placeholder={`搜索时间`}
  83. value={selectedKeys[0]}
  84. onChange={dateString => setSelectedKeys(dateString ? [dateString] : [])}
  85. onPressEnter={() => this.handleSearch(selectedKeys, confirm)}
  86. style={{ width: 188, marginBottom: 8, display: 'block' }}/>
  87. <Button
  88. type="primary"
  89. onClick={() => this.handleSearchtime(moment(selectedKeys[0]._d).format('YYYY-MM-DD'), confirm)}
  90. icon="search"
  91. size="small"
  92. style={{ width: 90, marginRight: 8 }}>
  93. 搜索
  94. </Button>
  95. <Button onClick={() => this.handleReset(clearFilters)} size="small" style={{ width: 90 }}>重置</Button>
  96. </div>
  97. ),
  98. filterIcon: filtered => (
  99. <Icon type="search" style={{ color: filtered ? '#1890ff' : undefined }} />
  100. ),
  101. onFilter: (value, record) => {
  102. return record.time.indexOf(moment(value).format('YYYY-MM-DD')) != -1},
  103. render: text => (
  104. <Highlighter
  105. highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
  106. searchWords={[this.state.searchText]}
  107. autoEscape
  108. textToHighlight={text.toString()}
  109. />
  110. ),
  111. },
  112. { title: '来电', key: 'callnum', dataIndex: 'callnum', ...this.getColumnSearchProps('callnum', '来电'), },
  113. { title: '时长', key: 'longtime', dataIndex: 'longtime', }
  114. ];
  115. const data = [
  116. { key: '1', time: '2019-07-30 16:31:05', callnum: '13546540218', longtime: '37秒' },
  117. { key: '2', time: '2019-06-24 22:08:05', callnum: '13546540218', longtime: '1分12秒' },
  118. { key: '3', time: '2017-08-15 12:31:05', callnum: '13546540218', longtime: '1分10秒' },
  119. { key: '4', time: '2016-12-30 06:15:00', callnum: '13546540218', longtime: '20秒' }
  120. ];
  121.  
  122. return (
  123. <Table className="accidentTable" columns={columns} dataSource={data} bordered size="small" />
  124. )
  125. }
  126. }

antd通过 filterDropdown 自定义--按某天时间搜索的更多相关文章

  1. python selenium 时间搜索框查询和日期大小比较

    在做selenium自动化的时候遇到 时间搜索框查询(如下图)并比较查询结果是否在输入的时间之类. 首先,第一步要做的就是选择时间,并获取到所选时间的文本信息 如上图所示,获取到的时间搜索框并没有文本 ...

  2. SpringJPA主键生成采用自定义ID,自定义ID采用年月日时间格式

    自定义主键生成策略 在entity类上添加注解 @Id @GeneratedValue(strategy = GenerationType.AUTO, generator = "custom ...

  3. Sublime2 DocBlocker插件在自动补全注释时输出自定义作者和当前时间等信息

    Sublime在进行前端开发时非常棒,当然也少不了众多的插件支持,DocBlocker是在Sublime平台上开发一款自动补全代码插件,支持JavaScript (including ES6), PH ...

  4. spring-redis-session 自定义 key 和过期时间

    对于分布式应用来说,最开始遇到的问题就是 session 的存储了,解决方案大致有如下几种 使用 spring-session 它可以把 session 存储到你想存储的位置,如 redis,mysq ...

  5. 小程序自定义pick(日期加时间组合)

    最近小程序有个需求要使用日期加时间的pick组件  翻了小程序文档似乎没有符合的 手写一个 新建组件picker.js: Component({ properties: { disabled: { t ...

  6. spring cache之自定义keys的过期时间

    spring @cacheable注解默认不支持方法级别的缓存失效时间,只能通过配置来配置全局的失效时间 如果需要实现对方法级别的缓存支持失效时间机制,有一种比较简单的方法,spring配置文件如下: ...

  7. 使用vue自定义组件以及动态时间

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. react中antd的表格自定义展开

    antd的表格官方案例中给出的都是固定的图表展开,在做需求的时候,需要使用点击最后一列,然后出现展开内容,实现效果图如下 在最开始设置一个全局变量 const keys = [];在设置列参数的函数中 ...

  9. 【antd】如何自定义antd组件form表单中Form.Item里的内容组件

    需求:现有一个form表单,但是其中一个元素比较复杂,并不是简单的输入框或者下拉框之类的.但是我又希望能通过form.validateFields().then()去获得它的值,就不需要在当前页面写大 ...

随机推荐

  1. [Cqoi2016]K远点对 K-Dtree

    4520: [Cqoi2016]K远点对 链接 bzoj 思路 用K-Dtree求点的最远距离. 求的时候顺便维护一个大小为2k的小根堆. 不知道为啥一定会对. 代码 #include <bit ...

  2. JVM参数笔记

    Java启动参数共分为三类: 其一是标准参数(-),所有的JVM实现都必须实现这些参数的功能,而且向后兼容: 其二是非标准参数(-X),默认jvm实现这些参数的功能,但是并不保证所有jvm实现都满足, ...

  3. Octopus501工作站 安装记录

    cmake libreadline-dev 没有运行程序,nvidia-smi查看GPU-Util 达到100% 解决方案:需要把驱动模式设置为常驻内存才可以,设置命令:nvidia-smi -pm ...

  4. [Gamma阶段]第九次Scrum Meeting

    Scrum Meeting博客目录 [Gamma阶段]第九次Scrum Meeting 基本信息 名称 时间 地点 时长 第九次Scrum Meeting 19/06/05 大运村寝室6楼 20min ...

  5. dubbo源码分析之过滤器Filter-12

    https://blog.csdn.net/luoyang_java/article/details/86682668 Dubbo 是阿里巴巴开源的一个高性能优秀的服务框架,使得应用可通过高性能的 R ...

  6. JVM探究之 —— 类加载器-双亲委派模型

    虚拟机设计团队把类加载阶段中的“通过一个类的全限定名来获取描述此类的二进制字节流”这个动作放到Java虚拟机外部去实现,以便让应用程序自己决定如何去获取所需要的类.实现这个动作的代码模块称为“类加载器 ...

  7. pdf怎么转换成word

    在线转换:https://app.xunjiepdf.com/pdf2word

  8. vs开启,Windows 10磁盘占用100%解决办法

    https://www.cnblogs.com/time-is-life/p/8888441.html 最后把Home Group相关的服务都改成禁用. 注意: 即使这两个服务没有启动也不行, 一定要 ...

  9. session与getSession()用法总结

    一.session 1.session的过期时间是从什么时候开始计算的?是从一登录就开始计算还是说从停止活动开始计算? 从session不活动的时候开始计算,如果session一直活动,session ...

  10. kotlin基础 字符串模板

    ${变量名} var tmp="字符串模板” print("今天学习${tmp}这个知识点")