Skip to content

Commit

Permalink
fix: onHeaderCell not working
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Dec 26, 2023
1 parent 9187819 commit 911a19a
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
130 changes: 130 additions & 0 deletions playground/src/73/index.tsx
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>
)
}
1 change: 1 addition & 0 deletions src/useAntdResizableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function useAntdResizableHeader<ColumnsType extends UARHColumnType = UARHColumnT
children: col?.children?.length ? getColumns(col.children) : undefined,
onHeaderCell: (column: ColumnsType) => {
return {
...col.onHeaderCell?.(column),
'data-index': column.dataIndex,
'title': typeof col?.title === 'string' ? col?.title : '',
'width': cache ? widthCache.current?.get(column[GETKEY] ?? '')?.width || column?.width : column?.width,
Expand Down

0 comments on commit 911a19a

Please sign in to comment.