@@ -49,6 +49,13 @@ declare module '@tanstack/table-core' {
49
49
th? : string | Record <string , string > | ((cell : Header <TData , TValue >) => string | Record <string , string >)
50
50
td? : string | Record <string , string > | ((cell : Cell <TData , TValue >) => string | Record <string , string >)
51
51
}
52
+ colspan? : {
53
+ td? : string | ((cell : Cell <TData , TValue >) => string )
54
+ }
55
+ rowspan? : {
56
+ td? : string | ((cell : Cell <TData , TValue >) => string )
57
+ }
58
+
52
59
}
53
60
54
61
interface TableMeta <TData > {
@@ -376,6 +383,14 @@ function onRowContextmenu(e: Event, row: TableRow<T>) {
376
383
}
377
384
}
378
385
386
+ function resolveValue<T , A = undefined >(prop : T | ((arg : A ) => T ), arg ? : A ): T | undefined {
387
+ if (typeof prop === ' function' ) {
388
+ // @ts-expect-error: TS can't know if prop is a function here
389
+ return prop (arg )
390
+ }
391
+ return prop
392
+ }
393
+
379
394
watch (
380
395
() => props .data , () => {
381
396
data .value = props .data ? [... props .data ] : []
@@ -405,10 +420,11 @@ defineExpose({
405
420
:data-pinned =" header.column.getIsPinned()"
406
421
:scope =" header.colSpan > 1 ? 'colgroup' : 'col'"
407
422
:colspan =" header.colSpan > 1 ? header.colSpan : undefined"
423
+ :rowspan =" header.rowSpan > 1 ? header.rowSpan : undefined"
408
424
:class =" ui.th({
409
425
class: [
410
426
props.ui?.th,
411
- typeof header.column.columnDef.meta?.class?.th === 'function' ? header.column.columnDef.meta.class.th(header) : header.column.columnDef.meta?.class?.th
427
+ resolveValue( header.column.columnDef.meta?.class?.th, header)
412
428
],
413
429
pinned: !!header.column.getIsPinned()
414
430
})"
@@ -436,10 +452,10 @@ defineExpose({
436
452
:class =" ui.tr({
437
453
class: [
438
454
props.ui?.tr,
439
- typeof tableApi.options.meta?.class?.tr === 'function' ? tableApi.options.meta.class.tr( row) : tableApi.options.meta?.class?.tr
455
+ resolveValue( tableApi.options.meta?.class?.tr, row)
440
456
]
441
457
})"
442
- :style =" typeof tableApi.options.meta?.style?.tr === 'function' ? tableApi.options.meta?.style?.tr( row) : tableApi.options.meta?.style?.tr "
458
+ :style =" resolveValue( tableApi.options.meta?.style?.tr, row)"
443
459
@click =" onRowSelect($event, row)"
444
460
@pointerenter =" onRowHover($event, row)"
445
461
@pointerleave =" onRowHover($event, null)"
@@ -449,14 +465,16 @@ defineExpose({
449
465
v-for =" cell in row.getVisibleCells()"
450
466
:key =" cell.id"
451
467
:data-pinned =" cell.column.getIsPinned()"
468
+ :colspan =" resolveValue(cell.column.columnDef.meta?.colspan?.td, cell)"
469
+ :rowspan =" resolveValue(cell.column.columnDef.meta?.rowspan?.td, cell)"
452
470
:class =" ui.td({
453
471
class: [
454
472
props.ui?.td,
455
- typeof cell.column.columnDef.meta?.class?.td === 'function' ? cell.column.columnDef.meta.class.td(cell) : cell.column.columnDef.meta?.class?.td
473
+ resolveValue( cell.column.columnDef.meta?.class?.td, cell)
456
474
],
457
475
pinned: !!cell.column.getIsPinned()
458
476
})"
459
- :style =" typeof cell.column.columnDef.meta?.style?.td === 'function' ? cell.column.columnDef.meta.style.td(cell) : cell.column.columnDef.meta?.style?.td "
477
+ :style =" resolveValue( cell.column.columnDef.meta?.style?.td, cell) "
460
478
>
461
479
<slot :name =" `${cell.column.id}-cell`" v-bind =" cell.getContext()" >
462
480
<FlexRender :render =" cell.column.columnDef.cell" :props =" cell.getContext()" />
@@ -497,14 +515,15 @@ defineExpose({
497
515
:key =" header.id"
498
516
:data-pinned =" header.column.getIsPinned()"
499
517
:colspan =" header.colSpan > 1 ? header.colSpan : undefined"
518
+ :rowspan =" header.rowSpan > 1 ? header.rowSpan : undefined"
500
519
:class =" ui.th({
501
520
class: [
502
521
props.ui?.th,
503
- typeof header.column.columnDef.meta?.class?.th === 'function' ? header.column.columnDef.meta.class.th(header) : header.column.columnDef.meta?.class?.th
522
+ resolveValue( header.column.columnDef.meta?.class?.th, header)
504
523
],
505
524
pinned: !!header.column.getIsPinned()
506
525
})"
507
- :style =" typeof header.column.columnDef.meta?.style?.th === 'function' ? header.column.columnDef.meta.style.th(header) : header.column.columnDef.meta?.style?.th "
526
+ :style =" resolveValue( header.column.columnDef.meta?.style?.th, header) "
508
527
>
509
528
<slot :name =" `${header.id}-footer`" v-bind =" header.getContext()" >
510
529
<FlexRender v-if =" !header.isPlaceholder" :render =" header.column.columnDef.footer" :props =" header.getContext()" />
0 commit comments