Skip to content

Commit fd3b690

Browse files
authored
fix(ui5-table): fix JS error when there are less cells than columns (#841)
In case we have more columns declared, but less cells provided, a JS error is present and the ui5-table is not displayed at all.
1 parent 3f10b37 commit fd3b690

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

packages/main/src/TableRow.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,25 @@ class TableRow extends UI5Element {
8181
}
8282

8383
this._columnsInfo.forEach((info, index) => {
84+
const cell = this.cells[index];
85+
86+
if (!cell) {
87+
return;
88+
}
89+
8490
if (info.visible) {
85-
this.visibleCells.push(this.cells[index]);
86-
this.cells[index].firstInRow = (index === 0);
87-
this.cells[index].popined = false;
91+
this.visibleCells.push(cell);
92+
cell.firstInRow = (index === 0);
93+
cell.popined = false;
8894
} else if (info.demandPopin) {
8995
this.popinCells.push({
90-
cell: this.cells[index],
96+
cell,
9197
popinText: info.popinText,
9298
});
9399

94-
this.cells[index].popined = true;
100+
cell.popined = true;
95101
} else {
96-
this.cells[index].popined = false;
102+
cell.popined = false;
97103
}
98104
}, this);
99105

packages/main/test/sap/ui/webcomponents/main/pages/Table.html

+48
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,54 @@
162162
</ui5-table-column>
163163
</ui5-table>
164164

165+
<!-- 3 columns, but 1 cell -->
166+
<ui5-title>3 columns, but 1 cell</ui5-title>
167+
<ui5-table class="demo-table" id="tblLessCells">
168+
<ui5-table-column id="column-1" slot="columns">
169+
<ui5-label>City</ui5-label>
170+
</ui5-table-column>
171+
172+
<ui5-table-column id="column-2" slot="columns" min-width="500" popin-text="Supplier">
173+
<ui5-label>Supplier</ui5-label>
174+
</ui5-table-column>
175+
176+
<ui5-table-column id="column-3" slot="columns" min-width="500" popin-text="Country" demand-popin>
177+
<div class="column-content">
178+
<ui5-label>Country</ui5-label>
179+
</div>
180+
</ui5-table-column>
181+
182+
<ui5-table-row>
183+
<ui5-table-cell>Dublin</ui5-table-cell>
184+
</ui5-table-row>
185+
<ui5-table-row>
186+
<ui5-table-cell>Sofia</ui5-table-cell>
187+
</ui5-table-row>
188+
<ui5-table-row>
189+
<ui5-table-cell>London</ui5-table-cell>
190+
</ui5-table-row>
191+
</ui5-table>
192+
193+
<!-- 1 column, but 3 cells -->
194+
<ui5-title>1 column, but 3 cells</ui5-title>
195+
<ui5-table class="demo-table" id="tblLessColumns">
196+
<ui5-table-column id="column-1" slot="columns">
197+
<ui5-label>City</ui5-label>
198+
</ui5-table-column>
199+
200+
<ui5-table-row>
201+
<ui5-table-cell>Dublin</ui5-table-cell>
202+
<ui5-table-cell>Sofia</ui5-table-cell>
203+
<ui5-table-cell>London</ui5-table-cell>
204+
</ui5-table-row>
205+
<ui5-table-row>
206+
<ui5-table-cell>Madrid</ui5-table-cell>
207+
<ui5-table-cell>Rome</ui5-table-cell>
208+
<ui5-table-cell>Barcelona</ui5-table-cell>
209+
</ui5-table-row>
210+
211+
</ui5-table>
212+
165213

166214
<script>
167215
"use strict";

packages/main/test/specs/Table.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ describe("Table general interaction", () => {
2929

3030
assert.strictEqual(noDataRow.isExisting(), true, 'noData div is present');
3131
});
32+
33+
it("tests if table with more columns than cells is rendered", () => {
34+
const tblLessCells = browser.$("#tblLessCells");
35+
assert.equal(tblLessCells.isExisting(), true, 'table with more columns is rendered without JS errors.');
36+
});
3237
});

0 commit comments

Comments
 (0)