@@ -367,7 +367,7 @@ export const ToniqListTable = defineToniqElement<ListTableInputs>()({
367
367
} ;
368
368
} ,
369
369
isPainting : false ,
370
- itemsPainted : 0 ,
370
+ isStillPainting : true ,
371
371
pageCountKey : 0 ,
372
372
tableListLeft : 0 ,
373
373
} ,
@@ -383,7 +383,7 @@ export const ToniqListTable = defineToniqElement<ListTableInputs>()({
383
383
} , state . rowStyles ) ,
384
384
} ) ;
385
385
} ,
386
- renderCallback ( { inputs, state, updateState, events, dispatch} ) {
386
+ renderCallback ( { inputs, state, updateState, events, dispatch, host } ) {
387
387
const enabledColumns = inputs . columns . filter ( ( column ) => ! column . disabled ) ;
388
388
// Duplicate first entry for the header column
389
389
const rows = [
@@ -463,75 +463,32 @@ export const ToniqListTable = defineToniqElement<ListTableInputs>()({
463
463
enabledColumns ,
464
464
( item , index ) => index ,
465
465
( item , index ) => {
466
- const contents = row . cells [ item . key as keyof typeof row ] ;
466
+ const itemKey = item . key as keyof typeof row ;
467
+ const contents = row . cells [ itemKey ] ;
467
468
468
469
const rowItemLeftStyle = css `
469
- left: ${ unsafeCSS (
470
- `${ state . rowStyles [ item . key as string ] ?. left } px` ,
471
- ) } ;
470
+ left: ${ unsafeCSS ( `${ state . rowStyles [ itemKey ] ?. left } px` ) } ;
472
471
` ;
473
472
474
473
const rowItemMinWidthStyle = css `
475
474
min-width: ${ index >= enabledColumns . length - 1
476
475
? unsafeCSS ( 'unset' )
477
- : unsafeCSS ( `${ state . rowStyles [ item . key as string ] ?. width } px` ) } ;
476
+ : unsafeCSS ( `${ state . rowStyles [ itemKey ] ?. width } px` ) } ;
478
477
` ;
479
478
480
479
return html `
481
480
< div
481
+ data-column =${ itemKey }
482
482
class =${ classMap ( {
483
483
'row-item' : true ,
484
484
sticky : ! ! item . option ?. sticky && state . canScroll ,
485
485
fill : ! ! item . option ?. spaceEvenly ,
486
486
} ) }
487
487
style=${ ifDefined (
488
488
rowItemLeftStyle || rowItemMinWidthStyle
489
- ? `${ rowItemLeftStyle } ${ rowItemMinWidthStyle } `
489
+ ? `${ rowItemLeftStyle ? rowItemLeftStyle : '' } ${ rowItemMinWidthStyle ? rowItemMinWidthStyle : '' } `
490
490
: undefined ,
491
491
) }
492
- ${ onResize ( ( event ) => {
493
- function updateRowStyles ( ) {
494
- const container = event . target ;
495
- if ( ! ( container instanceof HTMLElement ) ) {
496
- throw new Error ( 'onResize event had no target' ) ;
497
- }
498
-
499
- const left = container . getBoundingClientRect ( ) . left ;
500
-
501
- const currentWidth = (
502
- container . querySelector (
503
- '.row-content' ,
504
- ) as HTMLElement
505
- ) . getBoundingClientRect ( ) . width ;
506
-
507
- if (
508
- ! state . rowStyles [ item . key as string ] ?. width ||
509
- currentWidth >
510
- ( state . rowStyles [ item . key as string ]
511
- ?. width as number )
512
- ) {
513
- updateState ( {
514
- rowStyles : {
515
- ...state . rowStyles ,
516
- [ item . key ] : {
517
- width : currentWidth ,
518
- left : state . tableListLeft
519
- ? left - state . tableListLeft
520
- : left ,
521
- } ,
522
- } ,
523
- } ) ;
524
- }
525
- }
526
- if ( rowIndex < 2 || ! inputs . nonBlocking ) {
527
- setTimeout ( ( ) => {
528
- updateRowStyles ( ) ;
529
- updateState ( {
530
- itemsPainted : state . itemsPainted + 1 ,
531
- } ) ;
532
- } , 0 ) ;
533
- }
534
- } ) }
535
492
>
536
493
< div
537
494
class =${ classMap ( {
@@ -558,8 +515,8 @@ export const ToniqListTable = defineToniqElement<ListTableInputs>()({
558
515
` ;
559
516
}
560
517
561
- const isStillPainting = state . itemsPainted < enabledColumns . length * rows . length ;
562
- const isLoading = ( inputs . nonBlocking ? false : isStillPainting ) || ! ! inputs . showLoading ;
518
+ const isLoading =
519
+ ( inputs . nonBlocking ? false : state . isStillPainting ) || ! ! inputs . showLoading ;
563
520
return html `
564
521
< div
565
522
class =${ classMap ( {
@@ -574,6 +531,45 @@ export const ToniqListTable = defineToniqElement<ListTableInputs>()({
574
531
} ) }
575
532
${ onResize ( ( event ) => {
576
533
tableUpdate ( event . target ) ;
534
+
535
+ setTimeout ( ( ) => {
536
+ enabledColumns . forEach ( ( column ) => {
537
+ const columnKey = column . key as string ;
538
+
539
+ const rowItems = host . shadowRoot
540
+ . querySelector ( '.table-list' )
541
+ ?. querySelectorAll ( `.row-item[data-column="${ columnKey } "]` ) ;
542
+
543
+ if ( rowItems ) {
544
+ rowItems . forEach ( ( rowItem ) => {
545
+ const left = rowItem . getBoundingClientRect ( ) . left ;
546
+ const currentWidth = (
547
+ rowItem . querySelector ( '.row-content' ) as HTMLElement
548
+ ) . getBoundingClientRect ( ) . width ;
549
+ if (
550
+ ! state . rowStyles [ columnKey ] ?. width ||
551
+ currentWidth >
552
+ ( state . rowStyles [ columnKey ] ?. width as number )
553
+ ) {
554
+ updateState ( {
555
+ rowStyles : {
556
+ ...state . rowStyles ,
557
+ [ columnKey ] : {
558
+ width : currentWidth ,
559
+ left : state . tableListLeft
560
+ ? left - state . tableListLeft
561
+ : left ,
562
+ } ,
563
+ } ,
564
+ } ) ;
565
+ }
566
+ } ) ;
567
+ }
568
+ } ) ;
569
+ updateState ( {
570
+ isStillPainting : false ,
571
+ } ) ;
572
+ } , 0 ) ;
577
573
} ) }
578
574
${ listen ( 'scroll' , ( event ) => {
579
575
tableUpdate ( event . target ) ;
@@ -589,9 +585,7 @@ export const ToniqListTable = defineToniqElement<ListTableInputs>()({
589
585
rows ,
590
586
( item , index ) => index ,
591
587
( item : ListTableRow < any > , index : number ) => {
592
- return html `
593
- ${ listItem ( item , index ) }
594
- ` ;
588
+ return listItem ( item , index ) ;
595
589
} ,
596
590
) }
597
591
${ renderIf (
0 commit comments