1- import type { Table } from "@tanstack/react-table" ;
21import React from "react" ;
32
4- type TableRecord = Record < string , unknown > ;
5-
63type ColumnVisibilityPanelProps = {
7- table : Table < TableRecord > ;
84 isOpen : boolean ;
95 onClose : ( ) => void ;
106 title : string ;
117 closeAriaLabel : string ;
8+ headers : string [ ] ;
9+ visibleColumns : Set < string > ;
10+ onToggleColumn : ( colName : string ) => void ;
1211} ;
1312
1413export function ColumnVisibilityPanel ( {
15- table,
1614 isOpen,
1715 onClose,
1816 title,
1917 closeAriaLabel,
18+ headers,
19+ visibleColumns,
20+ onToggleColumn,
2021} : ColumnVisibilityPanelProps ) {
2122 if ( ! isOpen ) return null ;
22-
23- const columns = table
24- . getAllLeafColumns ( )
25- // Solo colonne che possono essere nascoste
26- . filter (
27- ( column ) => ( column . getCanHide ?.( ) ?? true ) && column . id !== "_dummy"
28- ) ;
29-
30- if ( ! columns . length ) return null ;
23+ if ( ! headers . length ) return null ;
3124
3225 return (
3326 < div className = "mid-table-filter-panel" >
@@ -43,26 +36,17 @@ export function ColumnVisibilityPanel({
4336 </ button >
4437 </ div >
4538 < div className = "mid-table-filter-body" >
46- { columns . map ( ( column ) => {
47- const headerLabel =
48- typeof column . columnDef . header === "string" ||
49- typeof column . columnDef . header === "number"
50- ? String ( column . columnDef . header )
51- : column . id ;
52-
39+ { headers . map ( ( colName ) => {
40+ const id = `mid-col-filter-${ colName } ` ;
5341 return (
54- < label
55- key = { column . id }
56- className = "mid-table-filter-item"
57- htmlFor = { `mid-col-filter-${ column . id } ` }
58- >
42+ < label key = { colName } className = "mid-table-filter-item" htmlFor = { id } >
5943 < input
60- id = { `mid-col-filter- ${ column . id } ` }
44+ id = { id }
6145 type = "checkbox"
62- checked = { column . getIsVisible ( ) }
63- onChange = { ( e ) => column . toggleVisibility ( e . target . checked ) }
46+ checked = { visibleColumns . has ( colName ) }
47+ onChange = { ( ) => onToggleColumn ( colName ) }
6448 />
65- < span className = "mid-table-filter-label" > { headerLabel } </ span >
49+ < span className = "mid-table-filter-label" > { colName } </ span >
6650 </ label >
6751 ) ;
6852 } ) }
0 commit comments