I am using redux and I am working on receiving data about membership information from action and processing it from components.
And try to process the data to a table.
I took data from user action and created a table through map functions... The incoming data contains
Data received as action ....
[{create_date : "2020-02-16T03:00:00Z", id:"test"},
{create_date : "2020-02-16T01:00:00Z", id:"test1"},
{create_date : "2020-02-14T03:00:00Z", id:"test2"},
{create_date : "2020-02-14T01:00:00Z", id:"test3"},
{create_date : "2020-02-14T00:00:01Z", id:"test4"},
{create_date : "2020-02-13T03:00:00Z", id:"test5"},
...]
As you can see, only create_date id is included.
I would like to order them by date and number them in order by next day after day.
For example, would like to print like this.
index create_date id
2 2020-02-16T03:00:00Z test
1 2020-02-16T01:00:00Z test1
3 2020-02-14T03:00:00Z test2
2 2020-02-14T01:00:00Z test3
1 2020-02-14T00:00:01Z test4
1 2020-02-13T03:00:00Z test5
How to insert index using if statement when using map function in react??
Mycode
render() {
const {user_list} = this.props;
console.log(user_list);
return (
<div className="animated fadeIn">
<Row>
<Col xl={12}>
<Card>
<CardHeader>
<i className="fa fa-align-justify"></i>userlist
</CardHeader>
<CardBody>
<Search searchUser={this.searchUser}/>
<Table responsive hover>
<thead>
<tr><th scope="col">Index</th>
<th scope="col">create_time</th>
<th scope="col">id/name</th>
</tr>
</thead>
<tbody>
{user_list.length > 0 && user_list.map((item, index) => (
<tr key={item.id.toString()}>
<td>{index}</td> //<<Does this change by date index.. if statement?
<td className={'datetime'}>
{item.hasOwnProperty('create_date') &&
<div>
{moment(item.create_date).format('YYYY-MM-DD')}<br/>
{moment(item.create_date).format('HH:mm')}
</div>
}
</td>
<td scope="row">
{item.displayName}
</td>
</tr>
))}
</tbody>
</Table>
</CardBody>
</Card>
</Col>
</Row>
</div>
)
}
....