-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9187819
commit 911a19a
Showing
2 changed files
with
131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { Table } from 'antd' | ||
import { useAntdResizableHeader } from 'use-antd-resizable-header' | ||
|
||
const columns: any[] = [ | ||
{ | ||
title: 'Name', | ||
dataIndex: 'name', | ||
key: 'name', | ||
width: 100, | ||
fixed: 'left', | ||
filters: [ | ||
{ | ||
text: 'Joe', | ||
value: 'Joe', | ||
}, | ||
{ | ||
text: 'John', | ||
value: 'John', | ||
}, | ||
], | ||
onFilter: (value, record) => record.name.indexOf(value) === 0, | ||
onHeaderCell: () => ({ | ||
style: { | ||
backgroundColor: 'red', | ||
color: '#fff', | ||
textAlign: 'center', | ||
}, | ||
onClick: () => { | ||
alert('clicked') | ||
}, | ||
}), | ||
}, | ||
{ | ||
title: 'Other', | ||
children: [ | ||
{ | ||
title: 'Age', | ||
dataIndex: 'age', | ||
key: 'age', | ||
width: 150, | ||
sorter: (a, b) => a.age - b.age, | ||
}, | ||
{ | ||
title: 'Address', | ||
children: [ | ||
{ | ||
title: 'Street', | ||
dataIndex: 'street', | ||
key: 'street', | ||
width: 150, | ||
}, | ||
{ | ||
title: 'Block', | ||
children: [ | ||
{ | ||
title: 'Building', | ||
dataIndex: 'building', | ||
key: 'building', | ||
width: 100, | ||
}, | ||
{ | ||
title: 'Door No.', | ||
dataIndex: 'number', | ||
key: 'number', | ||
width: 100, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'Company', | ||
children: [ | ||
{ | ||
title: 'Company Address', | ||
dataIndex: 'companyAddress', | ||
key: 'companyAddress', | ||
width: 200, | ||
}, | ||
{ | ||
title: 'Company Name', | ||
dataIndex: 'companyName', | ||
key: 'companyName', | ||
}, | ||
], | ||
}, | ||
{ | ||
title: 'Gender', | ||
dataIndex: 'gender', | ||
key: 'gender', | ||
width: 80, | ||
fixed: 'right', | ||
}, | ||
] | ||
|
||
const data: any[] = [] | ||
for (let i = 0; i < 100; i++) { | ||
data.push({ | ||
key: i, | ||
name: 'John Brown', | ||
age: i + 1, | ||
street: 'Lake Park', | ||
building: 'C', | ||
number: 2035, | ||
companyAddress: 'Lake Street 42', | ||
companyName: 'SoftLake Co', | ||
gender: 'M', | ||
}) | ||
} | ||
|
||
export default function App() { | ||
const { components, resizableColumns, tableWidth } = useAntdResizableHeader({ | ||
columns, | ||
}) | ||
|
||
return ( | ||
<div> | ||
<h1>Hello!</h1> | ||
<Table | ||
// columns={columns} | ||
columns={resizableColumns} | ||
components={components} | ||
dataSource={data} | ||
scroll={{ x: tableWidth }} | ||
/> | ||
</div> | ||
) | ||
} |
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