I have a table that displays a number of records from a json (dynamically). When you click on the desired row, you get a dialog with actions within it (records count, reject, approve, close dialog, next record, and previous record).
I have pretty much all of it working except the next and prev functionality. I thought a ++
and --
on the rowIndex
would fetch the next iteration (this is my angularJS thought process by the way, since I created this already in Angular but we are converting to ReactJS), but obviously, it doesn't work that way.
These are the functions I created, however, you can see a minimalist code snippet in my webpackbin that you can use to play around with it:
//Pull the next item
handleApprovalDialogNext = (rowIndex, openIndex, event) => {
this.setState(
{
openIndex: rowIndex++,
}, () => {this.setState({ open: true })}
)
};
//Pull the prev item
handleApprovalDialogPrev = (rowIndex, openIndex, event) => {
this.setState(
{
openIndex: rowIndex--,
}, () => {this.setState({ open: true })}
)
};
Here is a link to my webpackbin
p.s. Ideally, if the item is the first one, it shouldn't allow you to go back (perhaps, disabling the arrow icon). Same thing when you reach the end of the data.
Any help would be really appreciated.