Created
November 6, 2021 13:24
-
-
Save dayhaysoos/2fa146d61435da09d81e1ff5e560e2da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // column | |
| const columns = React.useMemo( | |
| () => [ | |
| { | |
| id: 'expander', | |
| accessor: '', | |
| Header: ({ getToggleAllRowsExpandedProps, isAllRowsExpanded }) => ( | |
| <span {...getToggleAllRowsExpandedProps()}> | |
| {isAllRowsExpanded ? '👇' : '👉'} | |
| </span> | |
| ), | |
| Cell: ({ row }) => { | |
| return ( | |
| // Use the row.canExpand and row.getToggleRowExpandedProps prop getter | |
| // to build the toggle for expanding a row | |
| row.canExpand ? ( | |
| <span | |
| {...row.getToggleRowExpandedProps({ | |
| style: { | |
| // We can even use the row.depth property | |
| // and paddingLeft to indicate the depth | |
| // of the row | |
| paddingLeft: `${row.depth * 2}rem` | |
| } | |
| })} | |
| > | |
| {row.isExpanded ? '👇' : '👉'} | |
| </span> | |
| ) : null | |
| ) | |
| } | |
| }, | |
| { | |
| Header: 'UID', | |
| accessor: 'id', | |
| disableFilters: true, | |
| Cell: function UID(props) { | |
| return props.value.split('-')[0] | |
| } | |
| }, | |
| { | |
| Header: 'Country', | |
| accessor: 'country' | |
| }, | |
| { | |
| Header: 'Education', | |
| accessor: 'education' | |
| }, | |
| { | |
| Header: 'Experience', | |
| accessor: 'years_of_exp' | |
| }, | |
| { | |
| Header: 'Skills', | |
| accessor: 'skills', | |
| Filter: TagFilter, | |
| Cell: function Skill(props) { | |
| return <Skills skills={props.value} /> | |
| } | |
| } | |
| ], | |
| [] | |
| ) | |
| // usetable hook | |
| const { | |
| getTableProps, | |
| getTableBodyProps, | |
| headerGroups, | |
| rows, | |
| prepareRow, | |
| state, | |
| state: { expanded }, | |
| visibleColumns, | |
| preGlobalFilteredRows, | |
| setGlobalFilter | |
| } = useTable( | |
| { | |
| columns, | |
| data, | |
| defaultColumn, | |
| filterTypes, | |
| useState | |
| }, | |
| useGlobalFilter, // useGlobalFilter! | |
| useFilters, | |
| useExpanded | |
| ) | |
Author
Thanks @derekr, I get an error that says global filter plugin is supposed to go before expanding.
I've added a value for accessor and it doesn't seem to change anything T_T
I have no idea what could possibly be wrong. I've been trying to get row.canExpand as true for days
Have you tried not setting accessor at all? If you don't get it working by tomorrow I can hop on a zoom or something to pair if you're down.
Author
I'd be down to pair! I'll let you know tomorrow.
I have tried with no accessor, too. No good :(
👍 Aight I'll hit you up tomorrow on twitter!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A couple things jump out:
accessorin the first element in your data is blank… wondering if that's throwing things off like short circuiting the expand logic assuming there is now data for that row.useExpandedto right after the table config inuseTablecall. IthinkI remember argument position was important (unexpectedly). This was probably me missing something during a debugging session, but I remember moving those around got my table working as expected.Here's a sample of my setup: