From 4dc89d6a5ec23451ae4c5c82b97a5b55bc454c58 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 9 Aug 2022 00:04:54 +0700 Subject: [PATCH] filter on some column --- package.json | 1 + src/views/DashboardPMOV1/tableDashboardv1.js | 117 ++++++++++++++++++- 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0e0e299..6fbea17 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "react-content-loader": "^6.0.3", "react-dom": "^16.14.0", "react-grid-layout": "^1.2.5", + "react-highlight-words": "^0.18.0", "react-leaflet": "^3.2.0", "react-leaflet-draw": "^0.19.8", "react-loader-spinner": "^3.1.5", diff --git a/src/views/DashboardPMOV1/tableDashboardv1.js b/src/views/DashboardPMOV1/tableDashboardv1.js index a212f2c..4f0e641 100644 --- a/src/views/DashboardPMOV1/tableDashboardv1.js +++ b/src/views/DashboardPMOV1/tableDashboardv1.js @@ -2,12 +2,20 @@ import '../../../node_modules/react-grid-layout/css/styles.css'; import '../../../node_modules/react-resizable/css/styles.css'; import './../DashboardPMO/Dashboard.css'; import { BASE_OSPRO } from '../../const/ApiConst'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import axios from 'axios' -import { Table, Row, Col } from 'antd'; +import { Table, Row, Col, Button, Input, Space } from 'antd'; import { formatRibuanDecimal } from '../../const/CustomFunc.js'; import { Badge } from 'reactstrap'; import { Link } from "react-router-dom"; +import { SearchOutlined } from '@ant-design/icons'; +import Highlighter from 'react-highlight-words'; +import _ from "lodash"; + +const filterData = data => formatter => data.map(item => ({ + text: formatter(item), + value: formatter(item) +})) const TableDashboardV1 = () => { const token = localStorage.getItem("token") @@ -20,6 +28,104 @@ const TableDashboardV1 = () => { const [MANPOWERS, SET_MANPOWERS] = useState(0) const [dataTable, setDataTable] = useState([]) + const [searchText, setSearchText] = useState(''); + const [searchedColumn, setSearchedColumn] = useState(''); + const searchInput = useRef(null); + + const handleSearch = (selectedKeys, confirm, dataIndex) => { + confirm(); + setSearchText(selectedKeys[0]); + setSearchedColumn(dataIndex); + }; + + const handleReset = (clearFilters) => { + clearFilters(); + setSearchText(''); + }; + + const getColumnSearchProps = (dataIndex) => ({ + filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => ( +
+ setSelectedKeys(e.target.value ? [e.target.value] : [])} + onPressEnter={() => handleSearch(selectedKeys, confirm, dataIndex)} + style={{ + marginBottom: 8, + display: 'block', + }} + /> + + + + + +
+ ), + filterIcon: (filtered) => ( + + ), + onFilter: (value, record) => + record[dataIndex].toString().toLowerCase().includes(value.toLowerCase()), + onFilterDropdownVisibleChange: (visible) => { + if (visible) { + setTimeout(() => searchInput.current?.select(), 100); + } + }, + render: (text) => + searchedColumn === dataIndex ? ( + + ) : ( + text + ), + }); const getProjects = async () => { const URL = `${BASE_OSPRO}/api/project/list` @@ -40,11 +146,14 @@ const TableDashboardV1 = () => { {record.kode_sortname}
{text} , + ...getColumnSearchProps('nama'), }, { title: 'Project Manager', dataIndex: 'projectManager', key: 'projectManager', + filters: _.uniqWith(filterData(dataTable)(i => i.projectManager), _.isEqual), + onFilter: (value, record) => record.projectManager.indexOf(value) === 0, }, { title: 'Planned Interval', @@ -88,7 +197,9 @@ const TableDashboardV1 = () => { } else { return Danger } - } + }, + filters: _.uniqWith(filterData(dataTable)(i => i.costHealth), _.isEqual), + onFilter: (value, record) => record.costHealth.indexOf(value) === 0, }, { title: 'Progress',