react-native-sortable-list
react-native-sortable-list copied to clipboard
Getting current order of list
I need to load some array of items to react-native-sortable-list. Reorder it and then get the reordered result back as array. Can I do it?
你找到解决方案了吗?
Take a look at onChangeOrder and onReleaseRow, u can save the order and build reordered result by yourself
Did anyone find a solution?
@mayankbaiswar-CSE What @Daimension said. You can use onChangeOrder if you want the new order as you are dragging it around. You can use onReleaseRow if you just want the new order once dropped.
`onChangeOrder = (nextOrder) => { console.log('next order - ',nextOrder) }
onReleaseRow = (key, currentOrder) => { console.log('current order - ',currentOrder) }`
<SortableList style={styles.list} contentContainerStyle={styles.contentContainer} data={data} renderRow={this._renderRow} onChangeOrder={this.onChangeOrder} onReleaseRow={this.onReleaseRow} />
Further expanding on @nh83012001 and @Daimension's explanation using component state to rerender: Use in component:
<SortableList
...
onReleaseRow={this.onRelease}
...
/>
onRelease function:
onRelease = (key, currentOrder) =>{
let sorted = [];
currentOrder.forEach(k => {
this.state.items.forEach((item, index) => {
if (index.toString() === k){
sorted.push(item);
}
})
})
this.setState({ items: sorted })
}