forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 1
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
virtual
(ant-design#44349)
* chore: update demo * chore: adjust fixed style * chore: opt scroll height * chore: clean up * chore: update demo * chore: bump rc-virtual-list * chore: update deps * chore: bump rc-table * fix: clean up * chore: fix demo * test: add test case
- Loading branch information
Showing
15 changed files
with
302 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { genVirtualTable } from 'rc-table'; | ||
import type { InternalTableProps } from '../InternalTable'; | ||
|
||
/** | ||
* Same as `rc-table` but we modify trigger children update logic instead. | ||
*/ | ||
export default genVirtualTable((prev, next) => { | ||
const { _renderTimes: prevRenderTimes } = prev as InternalTableProps<any>; | ||
const { _renderTimes: nextRenderTimes } = next as InternalTableProps<any>; | ||
|
||
return prevRenderTimes !== nextRenderTimes; | ||
}); |
2 changes: 1 addition & 1 deletion
2
components/table/RcTable.tsx → components/table/RcTable/index.tsx
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,39 @@ | ||
import React from 'react'; | ||
|
||
import Table from '..'; | ||
import { render } from '../../../tests/utils'; | ||
|
||
describe('Table.Virtual', () => { | ||
it('should work', () => { | ||
const { container } = render( | ||
<Table | ||
virtual | ||
scroll={{ x: 100, y: 100 }} | ||
columns={[ | ||
{ | ||
dataIndex: 'key', | ||
}, | ||
]} | ||
dataSource={[ | ||
{ | ||
key: 'bamboo', | ||
}, | ||
]} | ||
/>, | ||
); | ||
|
||
expect(container.querySelectorAll('.rc-virtual-list-holder .ant-table-cell')).toHaveLength(1); | ||
expect(container.querySelector('.rc-virtual-list-holder .ant-table-cell')?.textContent).toEqual( | ||
'bamboo', | ||
); | ||
}); | ||
|
||
// warning from `rc-table` | ||
it('warning if no scroll', () => { | ||
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
render(<Table virtual />); | ||
|
||
expect(errSpy).toHaveBeenCalledWith('Warning: `scroll.x` in virtual table must be number.'); | ||
errSpy.mockRestore(); | ||
}); | ||
}); |
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,3 +1,3 @@ | ||
import { extendTest } from '../../../tests/shared/demoTest'; | ||
|
||
extendTest('table', { skip: ['ajax.tsx'] }); | ||
extendTest('table', { skip: ['ajax.tsx', 'virtual-list.tsx'] }); |
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,3 +1,3 @@ | ||
import demoTest from '../../../tests/shared/demoTest'; | ||
|
||
demoTest('table', { skip: ['ajax.tsx'] }); | ||
demoTest('table', { skip: ['ajax.tsx', 'virtual-list.tsx'] }); |
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,5 +1,5 @@ | ||
import { imageDemoTest } from '../../../tests/shared/imageTest'; | ||
|
||
describe('Table image', () => { | ||
imageDemoTest('table'); | ||
imageDemoTest('table', { skip: ['virtual-list.tsx'] }); | ||
}); |
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,14 +1,7 @@ | ||
## zh-CN | ||
|
||
通过 `react-window` 引入虚拟滚动方案,实现 100000 条数据的高性能表格。 | ||
通过 `virtual` 开启虚拟滚动,此时 `scroll.x` 与 `scroll.y` 必须设置且为 `number` 类型。 | ||
|
||
## en-US | ||
|
||
Integrate virtual scroll with `react-window` to achieve a high performance table of 100,000 data. | ||
|
||
<style> | ||
.virtual-table .ant-table-container:before, | ||
.virtual-table .ant-table-container:after { | ||
display: none; | ||
} | ||
</style> | ||
Set `virtual` to enable virtual scroll, and `scroll.x` and `scroll.y` must be set at the same time with `number` type. |
Oops, something went wrong.