Is there a possibility to connect to selectable tables so they are synchronised?
Hi,
Having two different Select Table (HOC), first with a goal to show all the data list, so you can click it (lets name it Row Picker), and the other table with showing only clicked data (name: Picked Rows).
First use case is that whenever you click something in Row Picker, it appears in the Picked Rows automatically. And it is easy to implement with state. Use case assume that the tags shown in Picked Rows are already toggled. Implementing the toggle is tricky and I have not yet found a solution (here I ask for help).
Second use case is that clicking the Picked Rows will remove the row from Picked Rows (easy) and remove the toggle in Row Picker (not yet found a solution). Finally both tables are synchronised.
Does anyone have idea how to face the two problems with have the rows already toggled in the start and synchronising the unclicking both ways (now only one way is working).
Thanks for help
I am not sure I completely understand what you want but it sound like you want the 2nd table to show what was selected in the first but then also want the ability to unselect an already selected row in the 2nd and make it unselected in the first.
Sort of like a column picker - where all the options are shown in the left and the "selected" are show in the right (but can be unselected from EITHER side.
I would not use selectTableHOC for this - it was only built as an example to show how to build a HOC and how to manage selection. You can use it s a guide for your own code.
What you need to do is build your own mechanism for this.
- You'l want two tables on the same page (obviously) - but they will be in the same component
- They will share the same
selectedstate - The "primary" table will display all the data and show the selected state for those selected - as well as having a handler to toggle the state on and off
- The "second" table will need the data filtered at
rendertime to only contain the data that matches the selected state - but the click handler will change the same sharedselectedstate.
The flow would be as follows:
- The use clicks something in the primary table
- The selected state is updated and will trigger a
render - Inside the
renderyou filter the data for the second table using the full data against theselectedvalues - The
renderthen will redraw the Primary with the full data set (showing what the selected state is for each row), and the Secondary with ONLY the data that is selected - If the user clicks something in the secondary table the handler will remove the entry from the
selectedstate which will trigger arender(and it will do the right thing)
In summary, it is all about sharing the selected state and filtering to only the selected for the secondary table.
HOWEVER - if this is about a side-by-side selection process (full list on the left and selections on the right) that could be done with lists, there are much better tools to do this than two RTs next to each other. For example: react-beautiful-dnd.
I actually managed to make it work without any code changing :) Only using the static getDerivedStateFromProps(nextProps, prevState) function :)
Thank you anyway for help!