I currently have a table and each cell has a button. Upon clicking the button, based on that particular day (Monday or Tuesday), class (class 1 or class 2), and name (Kev or Josh), how can I push an object related to that particular button in the table to a new page? Using, ReactJS + React Router + Redux, what would be the correct approach to this?
And when once navigated to the new page, the new page would then populate a table with the class information from the object passed in, related to button cell clicked.
Code:
http://jsfiddle.net/k7wbzc4j/16/
<table className="test-table">
<thead>
<tr>
<th>List</th>
<th colSpan="2">Monday</th>
<th colSpan="2">Tuesday</th>
</tr>
<tr>
<th>Names</th>
<th>Class 1</th><th>Class 2</th>
<th>Class 1</th><th>Class 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Kev</td>
<td><button>abc</button></td><td><button>def</button></td>
<td><button>ghi</button></td><td><button>jkl</button></td>
</tr>
<tr>
<td>Josh</td>
<td><button>mno</button></td><td><button>pqr</button></td>
<td><button>stu</button></td><td><button>vwx</button></td>
</tr>
</tbody>
</table>
Will accept and upvote answer. Thank you in advance
EDIT
Should the table rows data be structured like so and reference the object based on ID like the following? If so how can I locate that particular id object based on the cell location (with day, name, and class number taken into account)?
list: [
{
name: Kev
monday: {
class1: {
id: 0,
classTitle: abc,
number: class1,
info: {
time: 1,
classSize: 2,
}
},
class 2: {
id: 1,
classTitle: def,
number: class2,
info: {
time: 1,
classSize: 2,
}
}
},
tuesday: {
class1: {
id: 2,
classTitle: ghi,
number: class1,
info: {
time: 1,
classSize: 2,
}
},
class 2: {
id: 3,
classTitle: jkl,
number: class2,
info: {
time: 1,
classSize: 2,
}
}
},
},
{
name: Josh,
monday: {
class1: {
id: 4,
classTitle: mno,
number: class1,
info: {
time: 1,
classSize: 2,
}
},
class2: {
id: 5,
classTitle: pqr,
number: class2,
info: {
time: 1,
classSize: 2,
}
}
},
tuesday: {
class1: {
id: 6,
classTitle: stu,
number: class1,
info: {
time: 1,
classSize: 2,
}
},
class2: {
id: 7,
classTitle: vwx,
number: class2,
info: {
time: 1,
classSize: 2,
}
}
},
}
}
]
your JSFiddle doesn't use react-router or react-redux so nobody will be able to point to one particular place of your code and tell you what exactly to do differently.
that said, one typical way to do this is to use regular links (or react-router Links) inside your table instead of Buttons, where each link includes an
idparameter:/newpage/<id>. You then declare a react-router route which maps route to component:
. When the user visits, for example,
/newpage/123in your app then theNewPagecomponent will be rendered. React-router will inject aparamsprop that looks like:{classInfoId: 123}. You then fetch from your Redux store the class info object with an id of
123, and display it as you wish.