Skip to content

Commit 6cfb6e0

Browse files
committed
Issue 128 - Fix to incorrect table layout with rowSpan and colSpan
1 parent 06c3d49 commit 6cfb6e0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/layout-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ const { ColSpanCell, RowSpanCell } = Cell;
55
(function () {
66
function layoutTable(table) {
77
table.forEach(function (row, rowIndex) {
8+
let prevCell = null;
89
row.forEach(function (cell, columnIndex) {
910
cell.y = rowIndex;
10-
cell.x = columnIndex;
11+
cell.x = prevCell ? prevCell.x + 1 : columnIndex;
1112
for (let y = rowIndex; y >= 0; y--) {
1213
let row2 = table[y];
1314
let xMax = y === rowIndex ? columnIndex : row2.length;
@@ -17,6 +18,7 @@ const { ColSpanCell, RowSpanCell } = Cell;
1718
cell.x++;
1819
}
1920
}
21+
prevCell = cell;
2022
}
2123
});
2224
});

test/layout-manager-test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,48 @@ describe('layout-manager', function () {
106106
]);
107107
});
108108

109+
it('complex layout 2', function () {
110+
let table = [
111+
[
112+
{ c: 'a', rowSpan: 3 },
113+
{ c: 'b', rowSpan: 2 },
114+
{ c: 'cd', colSpan: 2 },
115+
{ c: 'e', rowSpan: 2 },
116+
],
117+
[{ c: 'c' }, { c: 'd' }],
118+
[{ c: 'b' }, { c: 'c' }, { c: 'd' }, { c: 'e' }],
119+
[{ c: 'a' }, { c: 'b' }, { c: 'c' }, { c: 'd' }, { c: 'e' }],
120+
];
121+
122+
layoutTable(table);
123+
124+
expect(table).toEqual([
125+
[
126+
{ c: 'a', y: 0, x: 0, rowSpan: 3 },
127+
{ c: 'b', y: 0, x: 1, rowSpan: 2 },
128+
{ c: 'cd', y: 0, x: 2, colSpan: 2 },
129+
{ c: 'e', y: 0, x: 4, rowSpan: 2 },
130+
],
131+
[
132+
{ c: 'c', y: 1, x: 2 },
133+
{ c: 'd', y: 1, x: 3 },
134+
],
135+
[
136+
{ c: 'b', y: 2, x: 1 },
137+
{ c: 'c', y: 2, x: 2 },
138+
{ c: 'd', y: 2, x: 3 },
139+
{ c: 'e', y: 2, x: 4 },
140+
],
141+
[
142+
{ c: 'a', y: 3, x: 0 },
143+
{ c: 'b', y: 3, x: 1 },
144+
{ c: 'c', y: 3, x: 2 },
145+
{ c: 'd', y: 3, x: 3 },
146+
{ c: 'e', y: 3, x: 4 },
147+
],
148+
]);
149+
});
150+
109151
it('maxWidth of single element', function () {
110152
let table = [[{}]];
111153
layoutTable(table);

0 commit comments

Comments
 (0)