@@ -404,6 +404,18 @@ const ResultsTable = ({
404404 rightStartWidth : 0 ,
405405 } ) ;
406406
407+ const viewsByColumn = useMemo (
408+ ( ) => Object . fromEntries ( views . map ( ( v ) => [ v . column , v ] ) ) ,
409+ [ views ] ,
410+ ) ;
411+
412+ const visibleColumns = useMemo ( ( ) => {
413+ const filtered = columns . filter (
414+ ( column ) => viewsByColumn [ column . key ] ?. mode !== "hidden" ,
415+ ) ;
416+ return filtered . length ? filtered : columns ;
417+ } , [ columns , viewsByColumn ] ) ;
418+
407419 const rafIdRef = useRef < number | null > ( null ) ;
408420 const throttledSetColumnWidths = useCallback ( ( update : ColumnWidths ) => {
409421 if ( rafIdRef . current !== null ) {
@@ -435,7 +447,7 @@ const ResultsTable = ({
435447 widths . map ( ( w ) => w . split ( " - " ) ) . filter ( ( p ) => p . length === 2 ) ,
436448 ) ;
437449 const allWidths : ColumnWidths = { } ;
438- const defaultWidth = `${ 100 / columns . length } %` ;
450+ const defaultWidth = `${ 100 / ( visibleColumns . length || columns . length ) } %` ;
439451 columns . forEach ( ( c ) => {
440452 allWidths [ c . uid ] = fromLayout [ c . uid ] || defaultWidth ;
441453 } ) ;
@@ -527,8 +539,8 @@ const ResultsTable = ({
527539 const minWidth = 40 ;
528540 const minPercent = ( minWidth / totalWidth ) * 100 ;
529541
530- const finalWidths : ColumnWidths = { } ;
531- const uids = columns . map ( ( c ) => c . uid ) ;
542+ const finalWidths : ColumnWidths = { ... columnWidths } ;
543+ const uids = visibleColumns . map ( ( c ) => c . uid ) ;
532544 uids . forEach ( ( uid ) => {
533545 const header = tableRef . current ?. querySelector (
534546 `thead td[data-column="${ uid } "]` ,
@@ -553,7 +565,7 @@ const ResultsTable = ({
553565 values : Object . entries ( finalWidths ) . map ( ( [ k , v ] ) => `${ k } - ${ v } ` ) ,
554566 } ) ;
555567 }
556- } , [ columns , parentUid , columnWidths ] ) ;
568+ } , [ parentUid , columnWidths , visibleColumns ] ) ;
557569
558570 const resultHeaderSetFilters = React . useCallback (
559571 ( fs : FilterData ) => {
@@ -653,7 +665,7 @@ const ResultsTable = ({
653665 >
654666 < thead style = { { background : "#eeeeee80" } } >
655667 < tr style = { { visibility : ! showInterface ? "collapse" : "visible" } } >
656- { columns . map ( ( c ) => (
668+ { visibleColumns . map ( ( c ) => (
657669 < ResultHeader
658670 key = { c . uid }
659671 c = { c }
@@ -676,14 +688,14 @@ const ResultsTable = ({
676688 parentUid = { parentUid }
677689 views = { views }
678690 onRefresh = { onRefresh }
679- columns = { columns }
691+ columns = { visibleColumns }
680692 onDragStart = { onDragStart }
681693 onDrag = { onDrag }
682694 onDragEnd = { onDragEnd }
683695 />
684696 { extraRowUid === r . uid && (
685697 < tr className = { `roamjs-${ extraRowType } -row roamjs-extra-row` } >
686- < td colSpan = { columns . length } >
698+ < td colSpan = { visibleColumns . length } >
687699 { extraRowUid && extraRowType === "context" ? (
688700 < ExtraContextRow uid = { extraRowUid } />
689701 ) : extraRowUid && extraRowType === "discourse" ? (
0 commit comments