import type { GetProp } from 'antd'; import { Button, Empty, ConfigProvider, Table } from 'antd'; import React, { useState } from 'react'; const genFakeData = (count = 5) => Array.from({ length: count }).map((_, index) => ({ key: index, name: `Edward King ${index}`, age: 32 + index, address: `London, Park Lane no. ${index}`, })); const renderEmpty: GetProp = (componentName) => { if (componentName === 'Table.filter' /** 👈 5.20.0+ */) { return ; } }; function App() { const [dataSource, setDataSource] = useState(genFakeData); const handleToggle = () => { setDataSource(dataSource.length ? [] : genFakeData(Math.floor(Math.random() * 10))); }; const columns: GetProp = [ { title: 'Name', dataIndex: 'name', key: 'name', }, { title: 'Age', dataIndex: 'age', key: 'age', filters: dataSource.length ? [ { text: '>=35', value: 'gte35' }, { text: '<18', value: 'lt18' }, ] : [], }, { title: 'Address', dataIndex: 'address', key: 'address', }, ]; const toggleButton = ( ); return ( {dataSource.length ? toggleButton : null}
{toggleButton}, }} /> ); } export default App;