Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/hooks/useColumns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,10 @@ function useColumns<RecordType>(
// >>> Insert expand column if not exist
if (!cloneColumns.includes(EXPAND_COLUMN)) {
const expandColIndex = expandIconColumnIndex || 0;
if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) {
cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN);
}
if (fixed === 'right') {
cloneColumns.splice(baseColumns.length, 0, EXPAND_COLUMN);
const insertIndex =
expandColIndex === 0 && fixed === 'right' ? baseColumns.length : expandColIndex;
if (insertIndex >= 0) {
cloneColumns.splice(insertIndex, 0, EXPAND_COLUMN);
}
}

Expand Down
24 changes: 21 additions & 3 deletions tests/ExpandRow.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ describe('Table.Expand', () => {
}),
);
const wrapper2 = mount(
createTable({
columns,
data,
scroll: { x: 903 },
expandable: { expandedRowRender, fixed: true, expandIconColumnIndex: 1 },
}),
);
const wrapper3 = mount(
createTable({
columns,
data,
Expand All @@ -227,10 +235,11 @@ describe('Table.Expand', () => {
}),
);
expect(wrapper.find('.rc-table-has-fix-left').length).toBe(0);
expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(0);
expect(wrapper2.find('.rc-table-has-fix-left').length).toBe(0);
expect(wrapper3.find('.rc-table-has-fix-right').length).toBe(0);
});

it('fixed in expandable Fixed in expandable', () => {
it('fixed in expandable', () => {
const columns = [
{ title: 'Name', dataIndex: 'name', key: 'name' },
{ title: 'Age', dataIndex: 'age', key: 'age' },
Expand All @@ -249,6 +258,14 @@ describe('Table.Expand', () => {
}),
);
const wrapper2 = mount(
createTable({
columns,
data,
scroll: { x: 903 },
expandable: { expandedRowRender, fixed: true },
}),
);
const wrapper3 = mount(
createTable({
columns,
data,
Expand All @@ -257,7 +274,8 @@ describe('Table.Expand', () => {
}),
);
expect(wrapper.find('.rc-table-has-fix-left').length).toBe(1);
expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(1);
expect(wrapper2.find('.rc-table-has-fix-left').length).toBe(1);
expect(wrapper3.find('.rc-table-has-fix-right').length).toBe(1);
});

describe('config expand column index', () => {
Expand Down
117 changes: 108 additions & 9 deletions tests/__snapshots__/ExpandRow.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ LoadedCheerio {
exports[`Table.Expand > does not crash if scroll is not set 1`] = `
LoadedCheerio {
"0": <div
class="rc-table rc-table-scroll-horizontal"
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left"
>
<div
class="rc-table-container"
Expand All @@ -148,13 +148,21 @@ LoadedCheerio {
style="overflow-x: auto; overflow-y: hidden;"
>
<table
style="min-width: 100%; table-layout: auto;"
style="min-width: 100%; table-layout: fixed;"
>
<colgroup />
<colgroup>
<col
class="rc-table-expand-icon-col"
/>
</colgroup>
<thead
class="rc-table-thead"
>
<tr>
<th
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
/>
<th
class="rc-table-cell"
scope="col"
Expand Down Expand Up @@ -210,11 +218,28 @@ LoadedCheerio {

</div>
</td>
<td
style="padding: 0px; border: 0px; height: 0px;"
>
<div
style="height: 0px; overflow: hidden;"
>

</div>
</td>
</tr>
<tr
class="rc-table-row rc-table-row-level-0"
data-row-key="0"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand All @@ -235,6 +260,14 @@ LoadedCheerio {
class="rc-table-row rc-table-row-level-0"
data-row-key="1"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand Down Expand Up @@ -290,7 +323,7 @@ LoadedCheerio {
exports[`Table.Expand > does not crash if scroll is not set 2`] = `
LoadedCheerio {
"0": <div
class="rc-table rc-table-scroll-horizontal"
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left"
>
<div
class="rc-table-container"
Expand All @@ -300,13 +333,21 @@ LoadedCheerio {
style="overflow-x: auto; overflow-y: hidden;"
>
<table
style="min-width: 100%; table-layout: auto;"
style="min-width: 100%; table-layout: fixed;"
>
<colgroup />
<colgroup>
<col
class="rc-table-expand-icon-col"
/>
</colgroup>
<thead
class="rc-table-thead"
>
<tr>
<th
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
/>
<th
class="rc-table-cell"
scope="col"
Expand Down Expand Up @@ -362,11 +403,28 @@ LoadedCheerio {

</div>
</td>
<td
style="padding: 0px; border: 0px; height: 0px;"
>
<div
style="height: 0px; overflow: hidden;"
>

</div>
</td>
</tr>
<tr
class="rc-table-row rc-table-row-level-0"
data-row-key="0"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand All @@ -387,6 +445,14 @@ LoadedCheerio {
class="rc-table-row rc-table-row-level-0"
data-row-key="1"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand Down Expand Up @@ -1117,7 +1183,7 @@ LoadedCheerio {
exports[`Table.Expand > work in expandable fix 1`] = `
LoadedCheerio {
"0": <div
class="rc-table rc-table-scroll-horizontal"
class="rc-table rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left"
>
<div
class="rc-table-container"
Expand All @@ -1127,13 +1193,21 @@ LoadedCheerio {
style="overflow-x: auto; overflow-y: hidden;"
>
<table
style="width: 903px; min-width: 100%; table-layout: auto;"
style="width: 903px; min-width: 100%; table-layout: fixed;"
>
<colgroup />
<colgroup>
<col
class="rc-table-expand-icon-col"
/>
</colgroup>
<thead
class="rc-table-thead"
>
<tr>
<th
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
/>
<th
class="rc-table-cell"
scope="col"
Expand Down Expand Up @@ -1189,11 +1263,28 @@ LoadedCheerio {

</div>
</td>
<td
style="padding: 0px; border: 0px; height: 0px;"
>
<div
style="height: 0px; overflow: hidden;"
>

</div>
</td>
</tr>
<tr
class="rc-table-row rc-table-row-level-0"
data-row-key="0"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand All @@ -1214,6 +1305,14 @@ LoadedCheerio {
class="rc-table-row rc-table-row-level-0"
data-row-key="1"
>
<td
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
style="position: sticky; left: 0px;"
>
<span
class="rc-table-row-expand-icon rc-table-row-collapsed"
/>
</td>
<td
class="rc-table-cell"
>
Expand Down