-
Notifications
You must be signed in to change notification settings - Fork 353
fix: conflict of rowspan and expand (#4200) #4319
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
Open
Huauauaa
wants to merge
2
commits into
opentiny:dev
Choose a base branch
from
Huauauaa:fix/table
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+352
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| .DS_Store | ||
| node_modules | ||
| .pnpm-store/ | ||
| dist/ | ||
| dist2/ | ||
| dist2.7/ | ||
|
|
||
71 changes: 71 additions & 0 deletions
71
examples/sites/demos/pc/app/grid/span/row-span-with-expand-composition-api.vue
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,71 @@ | ||
| <template> | ||
| <tiny-grid :row-span="rowSpanFields" :data="tableData"> | ||
| <tiny-grid-column type="index" width="60"></tiny-grid-column> | ||
| <tiny-grid-column type="expand" width="60"> | ||
| <template #default="{ row }"> | ||
| <ul> | ||
| <li> | ||
| <span>公司名称:</span> | ||
| <span>{{ row.name }}</span> | ||
| </li> | ||
| <li> | ||
| <span>区域:</span> | ||
| <span>{{ row.area }}</span> | ||
| </li> | ||
| <li> | ||
| <span>城市:</span> | ||
| <span>{{ row.city }}</span> | ||
| </li> | ||
| </ul> | ||
| </template> | ||
| </tiny-grid-column> | ||
| <tiny-grid-column field="area" title="区域"></tiny-grid-column> | ||
| <tiny-grid-column field="province" title="省份"></tiny-grid-column> | ||
| <tiny-grid-column field="city" title="城市"></tiny-grid-column> | ||
| <tiny-grid-column field="name" title="公司名称"></tiny-grid-column> | ||
| </tiny-grid> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| import { ref } from 'vue' | ||
| import { TinyGrid, TinyGridColumn } from '@opentiny/vue' | ||
|
|
||
| const rowSpanFields = ref([{ field: 'area' }, { field: 'province' }]) | ||
| const tableData = ref([ | ||
| { | ||
| id: '1', | ||
| name: 'WWW 科技 YX 公司', | ||
| area: '华南区', | ||
| province: '广东省', | ||
| city: '深圳' | ||
| }, | ||
| { | ||
| id: '2', | ||
| name: 'RFV 有限责任公司', | ||
| area: '华南区', | ||
| province: '广东省', | ||
| city: '中山' | ||
| }, | ||
| { | ||
| id: '3', | ||
| name: 'YHN 科技 YX 公司', | ||
| area: '华南区', | ||
| province: '广东省', | ||
| city: '韶关' | ||
| }, | ||
| { | ||
| id: '4', | ||
| name: 'GFD 科技 YX 公司', | ||
| area: '华东区', | ||
| province: '福建省', | ||
| city: '福州' | ||
| }, | ||
| { | ||
| id: '5', | ||
| name: 'TGB 科技 YX 公司', | ||
| area: '华东区', | ||
| province: '福建省', | ||
| city: '龙岩' | ||
| } | ||
| ]) | ||
| </script> |
23 changes: 23 additions & 0 deletions
23
examples/sites/demos/pc/app/grid/span/row-span-with-expand.spec.js
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,23 @@ | ||
| import { test, expect } from '@playwright/test' | ||
|
|
||
| test('行合并与展开行:展开为全宽且不重叠', async ({ page }) => { | ||
| page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||
| await page.goto('grid-span#span-row-span-with-expand') | ||
|
|
||
| const areaCell = page.getByRole('cell', { name: '华南区' }).first() | ||
| await expect(areaCell).toHaveAttribute('rowspan', '3') | ||
|
|
||
| await page.getByRole('row', { name: /中山/ }).locator('.tiny-grid__expanded').click() | ||
| const expandRow = page.locator('.tiny-grid-body__expanded-row') | ||
| await expect(expandRow).toBeVisible() | ||
| await expect(page.locator('.tiny-grid-body__expanded-cell')).toContainText('中山') | ||
| await expect(expandRow.locator('td')).toHaveAttribute('colspan', '6') | ||
| await expect(areaCell).toHaveAttribute('rowspan', '2') | ||
|
|
||
| const shaoguanRow = page.getByRole('row', { name: /韶关/ }) | ||
| await expect(shaoguanRow.getByRole('cell', { name: '华南区' })).toBeVisible() | ||
|
|
||
| const expandBox = await expandRow.boundingBox() | ||
| const areaBox = await areaCell.boundingBox() | ||
| expect(expandBox.y).toBeGreaterThanOrEqual(areaBox.y + areaBox.height - 2) | ||
| }) |
80 changes: 80 additions & 0 deletions
80
examples/sites/demos/pc/app/grid/span/row-span-with-expand.vue
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,80 @@ | ||
| <template> | ||
| <tiny-grid :row-span="rowSpanFields" :data="tableData"> | ||
| <tiny-grid-column type="index" width="60"></tiny-grid-column> | ||
| <tiny-grid-column type="expand" width="60"> | ||
| <template #default="{ row }"> | ||
| <ul> | ||
| <li> | ||
| <span>公司名称:</span> | ||
| <span>{{ row.name }}</span> | ||
| </li> | ||
| <li> | ||
| <span>区域:</span> | ||
| <span>{{ row.area }}</span> | ||
| </li> | ||
| <li> | ||
| <span>城市:</span> | ||
| <span>{{ row.city }}</span> | ||
| </li> | ||
| </ul> | ||
| </template> | ||
| </tiny-grid-column> | ||
| <tiny-grid-column field="area" title="区域"></tiny-grid-column> | ||
| <tiny-grid-column field="province" title="省份"></tiny-grid-column> | ||
| <tiny-grid-column field="city" title="城市"></tiny-grid-column> | ||
| <tiny-grid-column field="name" title="公司名称"></tiny-grid-column> | ||
| </tiny-grid> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { TinyGrid, TinyGridColumn } from '@opentiny/vue' | ||
|
|
||
| export default { | ||
| components: { | ||
| TinyGrid, | ||
| TinyGridColumn | ||
| }, | ||
| data() { | ||
| return { | ||
| rowSpanFields: [{ field: 'area' }, { field: 'province' }], | ||
| tableData: [ | ||
| { | ||
| id: '1', | ||
| name: 'WWW 科技 YX 公司', | ||
| area: '华南区', | ||
| province: '广东省', | ||
| city: '深圳' | ||
| }, | ||
| { | ||
| id: '2', | ||
| name: 'RFV 有限责任公司', | ||
| area: '华南区', | ||
| province: '广东省', | ||
| city: '中山' | ||
| }, | ||
| { | ||
| id: '3', | ||
| name: 'YHN 科技 YX 公司', | ||
| area: '华南区', | ||
| province: '广东省', | ||
| city: '韶关' | ||
| }, | ||
| { | ||
| id: '4', | ||
| name: 'GFD 科技 YX 公司', | ||
| area: '华东区', | ||
| province: '福建省', | ||
| city: '福州' | ||
| }, | ||
| { | ||
| id: '5', | ||
| name: 'TGB 科技 YX 公司', | ||
| area: '华东区', | ||
| province: '福建省', | ||
| city: '龙岩' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| </script> |
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
100 changes: 100 additions & 0 deletions
100
packages/vue/src/grid/__tests__/split-rowspan-at-expand.test.ts
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,100 @@ | ||
| import { describe, expect, test } from 'vitest' | ||
| import { splitRowspanAtExpand } from '../src/composable/useCellSpan' | ||
|
|
||
| const col = (property) => ({ property, id: property }) | ||
|
|
||
| const cell = (rowspan, column, row, extra = {}) => ({ | ||
| attrs: { rowspan, colspan: rowspan > 0 ? 1 : 0, visible: rowspan > 0, _dataRowspan: rowspan, ...extra }, | ||
| params: { column, row } | ||
| }) | ||
|
|
||
| describe('splitRowspanAtExpand', () => { | ||
| test('no-op without expandeds', () => { | ||
| const area = col('area') | ||
| const data = [{ area: 'A' }, { area: 'A' }, { area: 'A' }] | ||
| const rows = [[cell(3, area, data[0])], [cell(0, area, data[1])], [cell(0, area, data[2])]] | ||
| splitRowspanAtExpand(rows, { expandeds: [], rowSpan: [{ field: 'area' }] }) | ||
| expect(rows.map((r) => r[0].attrs.rowspan)).toEqual([3, 0, 0]) | ||
| }) | ||
|
|
||
| test('expand without merges is identity', () => { | ||
| const city = col('city') | ||
| const r0 = { city: '深圳' } | ||
| const r1 = { city: '中山' } | ||
| const rows = [[cell(1, city, r0)], [cell(1, city, r1)]] | ||
| splitRowspanAtExpand(rows, { expandeds: [r0], rowSpan: [] }) | ||
| expect(rows.map((r) => r[0].attrs.rowspan)).toEqual([1, 1]) | ||
| expect(rows[0][0].attrs.colspan).toBe(1) | ||
| }) | ||
|
|
||
| test('splits merge when middle row expands (#4200)', () => { | ||
| const area = col('area') | ||
| const r0 = { area: '华南区' } | ||
| const r1 = { area: '华南区' } | ||
| const r2 = { area: '华南区' } | ||
| const rows = [[cell(3, area, r0)], [cell(0, area, r1)], [cell(0, area, r2)]] | ||
|
|
||
| splitRowspanAtExpand(rows, { | ||
| expandeds: [r1], | ||
| rowSpan: [{ field: 'area' }] | ||
| }) | ||
|
|
||
| expect(rows[0][0].attrs).toMatchObject({ rowspan: 2, visible: true }) | ||
| expect(rows[1][0].attrs).toMatchObject({ rowspan: 0, visible: false }) | ||
| expect(rows[2][0].attrs).toMatchObject({ rowspan: 1, visible: true }) | ||
| }) | ||
|
|
||
| test('expand on first row restarts merge below', () => { | ||
| const area = col('area') | ||
| const r0 = { area: 'A' } | ||
| const r1 = { area: 'A' } | ||
| const r2 = { area: 'A' } | ||
| const rows = [[cell(3, area, r0)], [cell(0, area, r1)], [cell(0, area, r2)]] | ||
|
|
||
| splitRowspanAtExpand(rows, { | ||
| expandeds: [r0], | ||
| rowSpan: [{ field: 'area' }] | ||
| }) | ||
|
|
||
| expect(rows[0][0].attrs.rowspan).toBe(1) | ||
| expect(rows[1][0].attrs).toMatchObject({ rowspan: 2, visible: true }) | ||
| expect(rows[2][0].attrs).toMatchObject({ rowspan: 0, visible: false }) | ||
| }) | ||
|
|
||
| test('expand on last row of group keeps full merge above', () => { | ||
| const area = col('area') | ||
| const r0 = { area: 'A' } | ||
| const r1 = { area: 'A' } | ||
| const r2 = { area: 'A' } | ||
| const rows = [[cell(3, area, r0)], [cell(0, area, r1)], [cell(0, area, r2)]] | ||
|
|
||
| splitRowspanAtExpand(rows, { | ||
| expandeds: [r2], | ||
| rowSpan: [{ field: 'area' }] | ||
| }) | ||
|
|
||
| expect(rows.map((r) => r[0].attrs.rowspan)).toEqual([3, 0, 0]) | ||
| }) | ||
|
|
||
| test('spanMethod covered cells stay hidden after expand', () => { | ||
| const a = col('a') | ||
| const b = col('b') | ||
| const r0 = { a: 1, b: 2 } | ||
| const r1 = { a: 1, b: 2 } | ||
| const covered = (column, row) => cell(0, column, row, { colspan: 0, visible: false, _dataRowspan: 0 }) | ||
| const rows = [ | ||
| [cell(2, a, r0, { colspan: 2, _dataRowspan: 2 }), covered(b, r0)], | ||
| [covered(a, r1), covered(b, r1)] | ||
| ] | ||
|
|
||
| splitRowspanAtExpand(rows, { | ||
| expandeds: [r0], | ||
| spanMethod: () => ({}) | ||
| }) | ||
|
|
||
| expect(rows[0][0].attrs).toMatchObject({ rowspan: 1, colspan: 2, visible: true }) | ||
| expect(rows[0][1].attrs).toMatchObject({ rowspan: 0, colspan: 0, visible: false }) | ||
| expect(rows[1][0].attrs).toMatchObject({ rowspan: 0, colspan: 0, visible: false }) | ||
| expect(rows[1][1].attrs).toMatchObject({ rowspan: 0, colspan: 0, visible: false }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.