meteor-utilities / react-list-container

Smart containers for React & Meteor
32 stars 8 forks source link

Question: filtering data #9

Closed yanickrochon closed 8 years ago

yanickrochon commented 8 years ago

I was expecting the selector props to fetch new data on change, however this is not the case.

For example, I use this to render a list of inventory items :

<ListContainer collection={InventoryItems} publication="inventory.items" selector={ this.state.selector }>
  <InventoryItemCollection />
</ListContainer>

Where the selector state may look like this : { sku: 'foo' } when filtering, or {} if no filters. However, the terms received on the subscription method is { options: { limit: 10 } }.

What is the proper way to search (filter) a collection, and can this be added in the documentation? If it is already documented, where is it?

SachaG commented 8 years ago

If I understand correctly, I think you just need to update the terms as well with the properties you want to filter by. If the terms don't change, then the data you receive from the server won't change either.

yanickrochon commented 8 years ago

Yeah, I finally got it, looking at the sources of ListContainer, I saw that terms and selector is quite different. I based myself on other pagination plugins as well, and got it to work. It would perhaps be appropriate to specify that selector is a client-side filter, whereas terms.* is the server-side data, and an example may be given to illustrate server-side filtering..

SachaG commented 8 years ago

Yeah, sorry it's not clearer. If it helps, Telescope uses ListContainer quite a bit: https://github.com/TelescopeJS/Telescope/search?utf8=%E2%9C%93&q=ListContainer