-
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.
feat: support
tooltipRender
for header cell ellipsis
break-change: 1. no need to import `css` anymore 2. package rename to `use-antd-resizable-header` fix bugs fix type 1. fix protable `hideInTable` bug 2. fix columns type
- Loading branch information
1 parent
35d581c
commit 3345589
Showing
26 changed files
with
604 additions
and
167 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
strict-peer-dependencies=false | ||
ignore-workspace-root-check=true |
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
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,23 @@ | ||
import ProTable, { type ProColumnType, type ProColumns } from '@ant-design/pro-table' | ||
import Table, { type ColumnsType } from 'antd/es/table' | ||
import { useState } from 'react' | ||
import { useAntdResizableHeader } from 'use-antd-resizable-header' | ||
|
||
export default function () { | ||
const [proCols, _setProCols] = useState<ProColumns<any>[]>([]) | ||
const {} = useAntdResizableHeader<ProColumnType>({ | ||
columns: proCols, | ||
}) | ||
|
||
const [cols, _setCols] = useState<ColumnsType>([{ title: 'Name', dataIndex: 'name' }]) | ||
const { resizableColumns } = useAntdResizableHeader<ColumnsType[number]>({ | ||
columns: cols, | ||
}) | ||
|
||
return ( | ||
<> | ||
<ProTable columns={proCols}></ProTable> | ||
<Table columns={resizableColumns} /> | ||
</> | ||
) | ||
} |
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,59 @@ | ||
import ProTable, { type ProColumns } from '@ant-design/pro-table' | ||
import { Tooltip } from 'antd' | ||
import { useMemo } from 'react' | ||
import { useAntdResizableHeader } from 'use-antd-resizable-header' | ||
|
||
const columns: ProColumns[] = [ | ||
{ | ||
title: 'title mmmmmmmmmmmmmmmmmm', | ||
dataIndex: 'name', | ||
width: 150, | ||
key: 'name', | ||
ellipsis: { | ||
showTitle: true, | ||
}, | ||
search: false, | ||
}, | ||
{ | ||
title: <div>title2</div>, | ||
dataIndex: 'street', | ||
key: 'street', | ||
valueType: 'dateRange', | ||
}, | ||
] | ||
|
||
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, | ||
remark: 'Lake Street 42', | ||
companyName: 'SoftLake Co', | ||
gender: 'M', | ||
}) | ||
} | ||
|
||
const ResizableTable = () => { | ||
const { components, resizableColumns, tableWidth } = useAntdResizableHeader({ | ||
columns: useMemo(() => columns, []), | ||
columnsState: { | ||
persistenceKey: 'localKey', | ||
persistenceType: 'localStorage', | ||
}, | ||
tooltipRender: (props) => <Tooltip {...props} />, | ||
}) | ||
return ( | ||
<> | ||
<div> | ||
<ProTable columns={resizableColumns} components={components} dataSource={data} scroll={{ x: tableWidth }} /> | ||
<Tooltip title={'123'} open={undefined} children='test'></Tooltip> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default ResizableTable |
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,144 @@ | ||
import ProTable, { type ProColumns } from '@ant-design/pro-table' | ||
import { Space, Tag } from 'antd' | ||
import { useMemo } from 'react' | ||
import request from 'umi-request' | ||
import { useAntdResizableHeader } from 'use-antd-resizable-header' | ||
|
||
type GithubIssueItem = { | ||
url: string | ||
id: number | ||
number: number | ||
title: string | ||
labels: { | ||
name: string | ||
color: string | ||
}[] | ||
state: string | ||
comments: number | ||
created_at: string | ||
updated_at: string | ||
closed_at?: string | ||
} | ||
|
||
const columns: ProColumns<GithubIssueItem>[] = [ | ||
{ | ||
dataIndex: 'index', | ||
valueType: 'indexBorder', | ||
width: 48, | ||
}, | ||
{ | ||
title: '标题', | ||
dataIndex: 'title', | ||
copyable: true, | ||
ellipsis: true, | ||
tip: '标题过长会自动收缩', | ||
width: 200, | ||
}, | ||
{ | ||
disable: true, | ||
title: '状态', | ||
dataIndex: 'state', | ||
filters: true, | ||
onFilter: true, | ||
ellipsis: true, | ||
width: 100, | ||
valueType: 'select', | ||
valueEnum: { | ||
all: { text: '超长'.repeat(50) }, | ||
open: { | ||
text: '未解决', | ||
status: 'Error', | ||
}, | ||
closed: { | ||
text: '已解决', | ||
status: 'Success', | ||
disabled: true, | ||
}, | ||
processing: { | ||
text: '解决中', | ||
status: 'Processing', | ||
}, | ||
}, | ||
}, | ||
{ | ||
disable: true, | ||
title: '标签', | ||
dataIndex: 'labels', | ||
width: 180, | ||
search: false, | ||
renderFormItem: (_, { defaultRender }) => { | ||
return defaultRender(_) | ||
}, | ||
render: (_, record) => ( | ||
<Space> | ||
{record.labels.map(({ name, color }) => ( | ||
<Tag color={color} key={name}> | ||
{name} | ||
</Tag> | ||
))} | ||
</Space> | ||
), | ||
}, | ||
{ | ||
title: '创建时间', | ||
key: 'aaa', | ||
dataIndex: 'created_at', | ||
valueType: 'dateRange', | ||
width: 200, | ||
hideInTable: true, | ||
search: { | ||
transform: (value) => { | ||
return { | ||
startTime: value[0], | ||
endTime: value[1], | ||
} | ||
}, | ||
}, | ||
}, | ||
{ | ||
title: '创建时间', | ||
dataIndex: 'created_at', | ||
valueType: 'date', | ||
width: 200, | ||
sorter: true, | ||
hideInSearch: true, | ||
}, | ||
|
||
{ | ||
title: '操作', | ||
valueType: 'option', | ||
key: 'option', | ||
render: (text, record, _, action) => [ | ||
<a href={record.url} target='_blank' rel='noopener noreferrer' key='view'> | ||
查看 | ||
</a>, | ||
], | ||
}, | ||
] | ||
|
||
export default () => { | ||
const { components, resizableColumns, tableWidth } = useAntdResizableHeader({ | ||
columns: useMemo(() => columns, []), | ||
columnsState: { | ||
persistenceType: 'localStorage', | ||
persistenceKey: 'aaaaa', | ||
}, | ||
}) | ||
return ( | ||
<ProTable<GithubIssueItem> | ||
columns={resizableColumns} | ||
components={components} | ||
scroll={{ x: tableWidth }} | ||
cardBordered | ||
request={async (params = {}, sort, filter) => { | ||
return request<{ | ||
data: GithubIssueItem[] | ||
}>('https://proapi.azurewebsites.net/github/issues', { | ||
params, | ||
}) | ||
}} | ||
rowKey='id' | ||
headerTitle='高级表格' | ||
/> | ||
) | ||
} |
Oops, something went wrong.