Skip to content

Commit d477d8e

Browse files
authored
Table: Allow to render cells without key when they have a render function (#8039)
2 parents 562a6ac + 8daa75a commit d477d8e

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

packages/components/src/components/table-stateless/component.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,35 +295,35 @@ export class KolTableStateless implements TableStatelessAPI {
295295
return max;
296296
}
297297

298-
private getThePrimaryHeadersWithKeysIfExists(headers: KoliBriTableHeaderCell[][]): KoliBriTableHeaderCell[] {
299-
const primaryHeadersWithKeys: KoliBriTableHeaderCell[] = [];
298+
private getThePrimaryHeadersWithKeyOrRenderFunction(headers: KoliBriTableHeaderCell[][]): KoliBriTableHeaderCell[] {
299+
const primaryHeaders: KoliBriTableHeaderCell[] = [];
300300

301301
headers.forEach((cells) => {
302302
cells.forEach((cell) => {
303-
if (typeof cell.key === 'string') {
304-
primaryHeadersWithKeys.push(cell);
303+
if (typeof cell.key === 'string' || typeof cell.render === 'function') {
304+
primaryHeaders.push(cell);
305305
}
306306
});
307307
});
308308

309-
return primaryHeadersWithKeys;
309+
return primaryHeaders;
310310
}
311311

312312
private getPrimaryHeaders(headers: KoliBriTableHeaders): KoliBriTableHeaderCell[] {
313-
let primaryHeadersWithKeys: KoliBriTableHeaderCell[] = this.getThePrimaryHeadersWithKeysIfExists(headers.horizontal ?? []);
313+
let primaryHeaders: KoliBriTableHeaderCell[] = this.getThePrimaryHeadersWithKeyOrRenderFunction(headers.horizontal ?? []);
314314

315315
/**
316316
* It is important to note that the rendering direction of the data is implicitly set,
317317
* if either the horizontal or vertical header cells have keys.
318318
*/
319319
this.horizontal = true;
320-
if (primaryHeadersWithKeys.length === 0) {
321-
primaryHeadersWithKeys = this.getThePrimaryHeadersWithKeysIfExists(headers.vertical ?? []);
322-
if (primaryHeadersWithKeys.length > 0) {
320+
if (primaryHeaders.length === 0) {
321+
primaryHeaders = this.getThePrimaryHeadersWithKeyOrRenderFunction(headers.vertical ?? []);
322+
if (primaryHeaders.length > 0) {
323323
this.horizontal = false;
324324
}
325325
}
326-
return primaryHeadersWithKeys;
326+
return primaryHeaders;
327327
}
328328

329329
private getColumnPositionMap(): Map<string, number> {
@@ -398,9 +398,9 @@ export class KolTableStateless implements TableStatelessAPI {
398398
if (
399399
typeof sortedPrimaryHeader[j] === 'object' &&
400400
sortedPrimaryHeader[j] !== null &&
401-
typeof sortedPrimaryHeader[j].key === 'string' &&
402401
typeof row === 'object' &&
403-
row !== null
402+
row !== null &&
403+
(typeof sortedPrimaryHeader[j].key === 'string' || typeof sortedPrimaryHeader[j].render === 'function')
404404
) {
405405
dataRow.push({
406406
...sortedPrimaryHeader[j],
@@ -414,9 +414,9 @@ export class KolTableStateless implements TableStatelessAPI {
414414
if (
415415
typeof sortedPrimaryHeader[i] === 'object' &&
416416
sortedPrimaryHeader[i] !== null &&
417-
typeof sortedPrimaryHeader[i].key === 'string' &&
418417
typeof data[j] === 'object' &&
419-
data[j] !== null
418+
data[j] !== null &&
419+
(typeof sortedPrimaryHeader[i].key === 'string' || typeof sortedPrimaryHeader[i].render === 'function')
420420
) {
421421
dataRow.push({
422422
...sortedPrimaryHeader[i],

packages/samples/react/src/components/table/render-cell.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ const HEADERS: KoliBriTableHeaders = {
8484
},
8585
{
8686
label: 'Action (react)',
87-
key: 'action',
8887
width: '20em',
8988

9089
/* Example 4: Render function using React */

packages/samples/react/src/components/table/sort-data.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const HEADERS_HORIZONTAL: KoliBriTableHeaders = {
1919
{ label: 'order', key: 'order', textAlign: 'center' },
2020
{
2121
label: 'date',
22-
key: 'date',
2322
textAlign: 'center',
2423
render: (_el, _cell, tupel) => DATE_FORMATTER.format((tupel as Data).date),
2524
compareFn: (data0, data1) => {
@@ -38,7 +37,6 @@ const HEADERS_VERTICAL: KoliBriTableHeaders = {
3837
{ label: 'order', key: 'order', textAlign: 'center' },
3938
{
4039
label: 'date',
41-
key: 'date',
4240
textAlign: 'center',
4341
render: (_el, _cell, tupel) => DATE_FORMATTER.format((tupel as Data).date),
4442
compareFn: (data0, data1) => {

0 commit comments

Comments
 (0)