-
-
Notifications
You must be signed in to change notification settings - Fork 619
feat: Table support expandedRowOffset #1284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
cad1f52
fix: cherry pick of fixing sticky issue (#1232)
zombieJ 542000c
7.50.3
zombieJ 1e2ec33
fix: virtual scroll logic (#1240)
zombieJ a056eaa
7.50.4
zombieJ 42c37bd
fix: 7.x header blank when using sticky or scroll.y (#1268)
linxianxi 17fa387
7.50.5
afc163 c1c85bc
feat: test
crazyair 664fa26
feat: test
crazyair 6f7c079
feat: test
crazyair 5bbddf1
feat: test
crazyair 300be98
feat: test
crazyair 2b1a5e6
feat: test
crazyair cd59d26
feat: test
crazyair 6fa36bd
feat: test
crazyair b012652
feat: test
crazyair de38a68
feat: test
crazyair 077ca36
feat: test
crazyair a2df007
feat: test
crazyair b2b71bb
feat: test
crazyair d37c667
feat: test
crazyair d775a2d
feat: test
crazyair a1da93e
feat: test
crazyair 0b1e581
feat: test
crazyair 81db207
feat: test
crazyair 4cf0247
feat: test
crazyair cbb3674
chore: merge branch
zombieJ 7142cdd
test: update snapshot
zombieJ 6a3c10a
chore: perf
zombieJ 9aef85d
test: update test case
zombieJ 92616be
chore: back of part
zombieJ a53a630
chore: fix ts
zombieJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,8 @@ | ||
| --- | ||
| title: expandedSticky | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|
|
||
| <code src="../examples/expandedSticky.tsx"></code> |
This file contains hidden or 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,95 @@ | ||
| import React, { useState } from 'react'; | ||
| import type { ColumnType } from 'rc-table'; | ||
| import Table from 'rc-table'; | ||
| import '../../assets/index.less'; | ||
|
|
||
| // 合并单元格 | ||
| export const getRowSpan = (source: (string | number | undefined)[] = []) => { | ||
| const list: { rowSpan?: number }[] = []; | ||
| let span = 0; | ||
| source.reverse().forEach((key, index) => { | ||
| span = span + 1; | ||
| if (key !== source[index + 1]) { | ||
| list.push({ rowSpan: span }); | ||
| span = 0; | ||
| } else { | ||
| list.push({ rowSpan: 0 }); | ||
| } | ||
| }); | ||
| return list.reverse(); | ||
| }; | ||
|
|
||
| const Demo = () => { | ||
| const [expandedRowKeys, setExpandedRowKeys] = useState<readonly React.Key[]>([]); | ||
|
|
||
| const data = [ | ||
| { key: 'a', a: '小二', d: '文零西路' }, | ||
| { key: 'b', a: '张三', d: '文一西路' }, | ||
| { key: 'c', a: '张三', d: '文二西路' }, | ||
| ]; | ||
| // const rowKeys = data.map(item => item.key); | ||
|
|
||
| // const rowSpanList = getRowSpan(data.map(item => item.a)); | ||
|
|
||
| const columns: ColumnType<Record<string, any>>[] = [ | ||
| { | ||
| title: '手机号', | ||
| dataIndex: 'a', | ||
| width: 100, | ||
| colSpan: 2, | ||
| // fixed: 'left', | ||
| onCell: (_, index) => { | ||
| // const { rowSpan = 1 } = rowSpanList[index]; | ||
| // const props: React.TdHTMLAttributes<HTMLTableCellElement> = {}; | ||
| // props.rowSpan = rowSpan; | ||
| // if (rowSpan >= 1) { | ||
| // let currentRowSpan = rowSpan; | ||
| // for (let i = index; i < index + rowSpan; i += 1) { | ||
| // const rowKey = rowKeys[i]; | ||
| // if (expandedRowKeys.includes(rowKey)) { | ||
| // currentRowSpan += 1; | ||
| // } | ||
| // } | ||
| // props.rowSpan = currentRowSpan; | ||
| // } | ||
| // return props; | ||
|
|
||
| if (index === 1) { | ||
| return { | ||
| rowSpan: 2, | ||
| }; | ||
| } else if (index === 2) { | ||
| return { | ||
| rowSpan: 0, | ||
| }; | ||
| } | ||
| }, | ||
| }, | ||
| { title: 'key', dataIndex: 'key2', colSpan: 0, width: 100 }, | ||
| Table.EXPAND_COLUMN, | ||
| { title: 'key', dataIndex: 'key' }, | ||
| { title: 'Address', fixed: 'right', dataIndex: 'd', width: 200 }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <div style={{ height: 10000 }}> | ||
| <h2>expanded & sticky</h2> | ||
| <Table<Record<string, any>> | ||
| rowKey="key" | ||
| sticky | ||
| scroll={{ x: 1000 }} | ||
| columns={columns} | ||
| data={data} | ||
| expandable={{ | ||
| expandedRowOffset: 2, | ||
| expandedRowKeys, | ||
| onExpandedRowsChange: keys => setExpandedRowKeys(keys), | ||
| expandedRowRender: record => <p style={{ margin: 0 }}>expandedRowRender: {record.key}</p>, | ||
| }} | ||
| className="table" | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Demo; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
建议添加数组边界检查
在第 98 行访问
rowKeys[i]时,应该确保索引不超出数组范围,以避免潜在的运行时错误。// Expandable row has offset if (expandedRowOffset) { const { rowSpan = 1 } = additionalCellProps; // For expandable row with rowSpan, // We should increase the rowSpan if the row is expanded if (expandable && rowSpan && colIndex < expandedRowOffset) { let currentRowSpan = rowSpan; for (let i = index; i < index + rowSpan; i += 1) { + if (i >= rowKeys.length) { + break; + } const rowKey = rowKeys[i]; if (expandedKeys.has(rowKey)) { currentRowSpan += 1; } } additionalCellProps.rowSpan = currentRowSpan; } }📝 Committable suggestion
🤖 Prompt for AI Agents