()
| 100 | describe('useReactTable', () => { |
| 101 | it('can toggle column visibility', () => { |
| 102 | const Table = () => { |
| 103 | const [data] = React.useState<Person[]>(() => [...defaultData]) |
| 104 | const [columns] = React.useState<typeof defaultColumns>(() => [ |
| 105 | ...defaultColumns, |
| 106 | ]) |
| 107 | const [columnVisibility, setColumnVisibility] = React.useState({}) |
| 108 | |
| 109 | const rerender = React.useReducer(() => ({}), {})[1] |
| 110 | |
| 111 | const table = useReactTable({ |
| 112 | data, |
| 113 | columns, |
| 114 | onColumnVisibilityChange: setColumnVisibility, |
| 115 | state: { |
| 116 | columnVisibility, |
| 117 | }, |
| 118 | getCoreRowModel: getCoreRowModel(), |
| 119 | // debug: true, |
| 120 | }) |
| 121 | |
| 122 | return ( |
| 123 | <div className="p-2"> |
| 124 | <div className="inline-block border border-black shadow rounded"> |
| 125 | <div className="px-1 border-b border-black"> |
| 126 | <label> |
| 127 | <input |
| 128 | {...{ |
| 129 | type: 'checkbox', |
| 130 | checked: table.getIsAllColumnsVisible(), |
| 131 | onChange: table.getToggleAllColumnsVisibilityHandler(), |
| 132 | }} |
| 133 | />{' '} |
| 134 | Toggle All |
| 135 | </label> |
| 136 | </div> |
| 137 | {table.getAllLeafColumns().map((column) => { |
| 138 | return ( |
| 139 | <div key={column.id} className="px-1"> |
| 140 | <label> |
| 141 | <input |
| 142 | {...{ |
| 143 | type: 'checkbox', |
| 144 | checked: column.getIsVisible(), |
| 145 | onChange: column.getToggleVisibilityHandler(), |
| 146 | }} |
| 147 | />{' '} |
| 148 | {column.id} |
| 149 | </label> |
| 150 | </div> |
| 151 | ) |
| 152 | })} |
| 153 | </div> |
| 154 | <div className="h-4" /> |
| 155 | <table> |
| 156 | <thead> |
| 157 | {table.getHeaderGroups().map((headerGroup) => ( |
| 158 | <tr key={headerGroup.id}> |
| 159 | {headerGroup.headers.map((header) => ( |
nothing calls this directly
no test coverage detected