Commit 0ff07b2
feat: replace defaultVisibleColumns/defaultPageSize with initialViewState (#21)
DataTableOptions supported construction-time defaults for visible columns
and page size, but not sort/filters/grouping — so a consumer wanting a
default sort had to call setViewState() as a separate priming step right
after construction, and resetView had no way to restore that default sort
since it wasn't a construction-time option the library knew about.
Replace defaultVisibleColumns/defaultPageSize with a single
initialViewState: TableViewState option, covering every view concern
(visible columns, column order, sort, filters, grouping, page/pageSize,
search) in one shape that resolveViewState now treats uniformly as the
fallback for any field a view omits. Since resetView/setViewState({}) and
construction-time seeding both go through resolveViewState, initialViewState
is now simultaneously "what a fresh table starts at" and "what a reset
restores" — closing the whole class of bug described in the issue.
Grouping a column via initialViewState.groupBy with no matching sorts
entry gets one auto-inserted (syncGroupSorts), mirroring what interactive
group.toggle already does, so a deterministic nesting order doesn't
require also hand-writing the matching sort. This only applies when
groupBy itself falls back to initialViewState (construction, reset, or a
setViewState call that leaves view.groupBy unset) — an explicit
view.groupBy (e.g. restoring a stored/shared view) is exempt, preserving
setViewState's existing contract.
getViewState()'s own omission logic (buildViewStateSnapshot) now deep-
compares every field against what resolveViewState({}, columns,
initialViewState) resolves to, rather than checking "is this field
non-empty" — this also fixes a latent bug where visibleCols was compared
against every column instead of the actual construction default.
Breaking change (pre-1.0, no compat shim, same precedent as the
Namespaced TableState migration): defaultVisibleColumns/defaultPageSize
are removed from every adapter's options. Updated all four adapters
(react/vue/solid/vanilla), their READMEs, CLAUDE.md, and all four demo
apps accordingly, and added core/adapter test coverage for the new
option and the resetView-restores-default-sort scenario.
Closes #20
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent 2272189 commit 0ff07b2
35 files changed
Lines changed: 887 additions & 361 deletions
File tree
- demo
- react/src
- solid/src
- vanilla/src
- vue/src
- packages
- core/src
- __tests__
- react
- src
- __tests__
- solid
- src
- __tests__
- vanilla
- src
- __tests__
- vue
- src
- __tests__
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | | - | |
| 447 | + | |
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
630 | | - | |
| 630 | + | |
631 | 631 | | |
632 | | - | |
633 | 632 | | |
634 | 633 | | |
635 | 634 | | |
| |||
645 | 644 | | |
646 | 645 | | |
647 | 646 | | |
648 | | - | |
| 647 | + | |
649 | 648 | | |
650 | | - | |
651 | 649 | | |
652 | 650 | | |
653 | 651 | | |
| |||
667 | 665 | | |
668 | 666 | | |
669 | 667 | | |
670 | | - | |
| 668 | + | |
671 | 669 | | |
672 | | - | |
673 | 670 | | |
674 | 671 | | |
675 | 672 | | |
| |||
696 | 693 | | |
697 | 694 | | |
698 | 695 | | |
699 | | - | |
| 696 | + | |
700 | 697 | | |
701 | | - | |
702 | 698 | | |
703 | 699 | | |
704 | 700 | | |
| |||
719 | 715 | | |
720 | 716 | | |
721 | 717 | | |
722 | | - | |
| 718 | + | |
723 | 719 | | |
724 | 720 | | |
725 | 721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
299 | | - | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | | - | |
| 447 | + | |
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
646 | | - | |
| 646 | + | |
647 | 647 | | |
648 | | - | |
649 | 648 | | |
650 | 649 | | |
651 | 650 | | |
| |||
661 | 660 | | |
662 | 661 | | |
663 | 662 | | |
664 | | - | |
| 663 | + | |
665 | 664 | | |
666 | | - | |
667 | 665 | | |
668 | 666 | | |
669 | 667 | | |
| |||
680 | 678 | | |
681 | 679 | | |
682 | 680 | | |
683 | | - | |
| 681 | + | |
684 | 682 | | |
685 | | - | |
686 | 683 | | |
687 | 684 | | |
688 | 685 | | |
| |||
704 | 701 | | |
705 | 702 | | |
706 | 703 | | |
707 | | - | |
| 704 | + | |
708 | 705 | | |
709 | | - | |
710 | 706 | | |
711 | 707 | | |
712 | 708 | | |
| |||
721 | 717 | | |
722 | 718 | | |
723 | 719 | | |
724 | | - | |
| 720 | + | |
725 | 721 | | |
726 | 722 | | |
727 | 723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
427 | | - | |
| 427 | + | |
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| |||
711 | 711 | | |
712 | 712 | | |
713 | 713 | | |
714 | | - | |
715 | | - | |
| 714 | + | |
716 | 715 | | |
717 | 716 | | |
718 | 717 | | |
| |||
725 | 724 | | |
726 | 725 | | |
727 | 726 | | |
728 | | - | |
729 | | - | |
| 727 | + | |
730 | 728 | | |
731 | 729 | | |
732 | 730 | | |
| |||
753 | 751 | | |
754 | 752 | | |
755 | 753 | | |
756 | | - | |
757 | | - | |
| 754 | + | |
758 | 755 | | |
759 | 756 | | |
760 | 757 | | |
| |||
769 | 766 | | |
770 | 767 | | |
771 | 768 | | |
772 | | - | |
773 | | - | |
| 769 | + | |
774 | 770 | | |
775 | 771 | | |
776 | 772 | | |
| |||
783 | 779 | | |
784 | 780 | | |
785 | 781 | | |
786 | | - | |
| 782 | + | |
787 | 783 | | |
788 | 784 | | |
789 | 785 | | |
| |||
819 | 815 | | |
820 | 816 | | |
821 | 817 | | |
822 | | - | |
| 818 | + | |
823 | 819 | | |
824 | 820 | | |
825 | 821 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
| 292 | + | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
543 | | - | |
544 | | - | |
| 543 | + | |
545 | 544 | | |
546 | 545 | | |
547 | 546 | | |
| |||
550 | 549 | | |
551 | 550 | | |
552 | 551 | | |
553 | | - | |
554 | | - | |
| 552 | + | |
555 | 553 | | |
556 | 554 | | |
557 | 555 | | |
558 | 556 | | |
559 | 557 | | |
560 | 558 | | |
561 | | - | |
562 | | - | |
| 559 | + | |
563 | 560 | | |
564 | 561 | | |
565 | 562 | | |
566 | 563 | | |
567 | 564 | | |
568 | 565 | | |
569 | | - | |
570 | | - | |
| 566 | + | |
571 | 567 | | |
572 | 568 | | |
573 | 569 | | |
574 | 570 | | |
575 | 571 | | |
576 | 572 | | |
577 | 573 | | |
578 | | - | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
579 | 577 | | |
580 | 578 | | |
581 | 579 | | |
| |||
0 commit comments