Sort my flatList by the hour

Asked

Viewed 411 times

0

I am filtering my flatlist by date (period), but want to put the hours in ascending order:

<FlatList
                style={{backgroundColor: 'white', marginTop: 10}}
                data={this.state.progr.data.filter(x => x.period === '2019-10-16T00:00:00.000-03:00')}
                renderItem={({item}) => this.renderItem({item})}
                keyExtractor = {(item, index) => item.id.toString()}
            />

The time coming from the api is with the name:only thing that matters there is the time I pull like this: {new Date(item.start_time). getHours()}

start_time: '019-09-12T14:00:00.000-03:00'

1 answer

0


Can do it this way:

data={this.state.progr.data.sort((a, b) => a.start_time > b.start_time).filter(x => x.period === '2019-10-16T00:00:00.000-03:00')}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.