-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting ListView's Datasource Does Not Rerender ListView #555
Comments
Have you tried using row IDs and passing them into dataSource.cloneWithRows as the second argument? |
I run into same problem like this. what I do is to dynamicly add item into the data. and then the render is not working correctly. and I fixed it the same way as you did:
|
I am also having issues with rowHasChanged. If I do this:
And then later:
I get |
@veddermatic you need to clone data[0], otherwise this is the same reference so ListViewDataSource can't tell the difference. Look for the many talks about immutability and react to have a better understanding of what is happening |
@vjeux Understood, but shouldn't the method |
I'm passing in an identity array, which contains object IDs, as the second argument of |
Can anyone provide a simple example of how to maintain a sort order with |
@willmcclellan Here's a quick example: let data = [
{
"id": "id:1",
"name": "John",
"age": 20
},
{
"id": "id:2",
"name": "Charles",
"age": 24
}
]
let identities = data.map(function(d) { return d.id; });
dataSource = dataSource.cloneWithRows(data, identities); Hope this helps |
@jamesfzhang thanks! |
Also some crude work on sorting by tapping column header (just on name for now). Something to do with this I suspect: facebook/react-native#555
What if none of the data has changed but you want to trigger a re-render because there is conditional logic deciding which data shows in each ListView row in your renderRow method? Something to simply re-render the ListView + renderRow seems useful here. |
This logic must be using some data in order to decide what to render, the idea is to put this data inside of the datasource or at least in your shouldRowUpdate function. |
As far as I can tell, when I
sort
thedataSource
and then calldataSource.cloneWithRows
, it thinks nothing has changed, and thus does not rerender theListView
.Some background:
I fetch some data, which returns:
[{price: 10}, {price: 9}...]
. After which i set the state with the new data:this.setState({dataSource: this.state.dataSource.cloneWithRows(data)})
. Lets pretend this data is completely sorted. If i reverse the data and set the state, it will not rerender:this.setState({dataSource: this.state.dataSource.cloneWithRows(data.reverse())})
BUT: After messing around a bit, i made a change to the dataSource, like so:
...which I know is hackery... But now I can toggle
reverse
back and forth and it works!Am I missing something here? Or is this perhaps a side effect of the
ListView
's optimizations?The text was updated successfully, but these errors were encountered: