-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(table): support sorter and filter controll
- Loading branch information
lihang
committed
May 27, 2021
1 parent
75abb96
commit e739ff5
Showing
11 changed files
with
142 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useState } from 'react'; | ||
import { SortOrder } from '../interface'; | ||
import Table from '../index'; | ||
|
||
|
||
const dataSource = Array.from({ length: 1000 }, (_, key) => ({ a: key, b: key, c: key, d: key })); | ||
|
||
|
||
const ControlledTable = () => { | ||
const [sortOrder, setSortOrder] = useState<SortOrder>(null); | ||
const [sortOrder2, setSortOrder2] = useState<SortOrder>(null); | ||
const [filters, setFilters] = useState<string[]>([]); | ||
const columns = [ | ||
{ | ||
title: 'A', | ||
dataIndex: 'a', | ||
key: 'a', | ||
sorter: (a: any, b: any) => a.a - b.a, | ||
sortOrder | ||
}, | ||
{ | ||
title: 'B', | ||
dataIndex: 'b', | ||
key: 'b', | ||
sorter: (a: any, b: any) => a.a - b.a, | ||
sortOrder: sortOrder2 | ||
}, | ||
{ | ||
title: 'C', | ||
dataIndex: 'c', | ||
key: 'c', | ||
filteredValue: filters, | ||
filters: ['奇数', '偶数'], | ||
onFilter: (value: any, record: any) => { | ||
if (value === '奇数') { | ||
return record.c % 2 === 1; | ||
} | ||
if (value === '偶数') { | ||
return record.c % 2 === 0; | ||
} | ||
return false; | ||
}, | ||
}, | ||
{ | ||
title: 'D', | ||
dataIndex: 'd', | ||
key: 'd', | ||
}, | ||
]; | ||
|
||
return ( | ||
<Table | ||
dataSource={dataSource} | ||
columns={columns} | ||
onChange={(p, s, f) => { | ||
if(s?.key === 'a') { | ||
setSortOrder(s.sortOrder); | ||
} | ||
if(s?.key === 'b') { | ||
setSortOrder2(s.sortOrder); | ||
} | ||
if(f.c) { | ||
setFilters(f.c) | ||
} | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { ControlledTable }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.