I am trying to do a simple table sort. Right now I would not like to use reactive table, because I want to understand how to sort a Collection. I am new at meteor . JS
I created a Collection
@robfallows, @pahans sorry for reviving this thread. I see how this works using a reactive variable, but I donât get why we need a reactive variable in the first place â and running a sort command on a Mongo Collection cursor doesnât achieve the same effect.
To my understanding when I return a Collection cursor in my template helper, that cursor is reactive. So when I run a mongo sort function without using a reactive var, e.g.
Products.find({}, { sort: { name: -1 } })
why doesnât this change still trigger a reflow of the UI? (I tested this out by running sort commands against a Collection in the console; the page doesnât re-render.)
A template helper establishes a reactive dependency on the cursor (if the cursor changes, the helper is re-run). However, the cursor itself is not reactive.
In the example above, another reactive dependency (the ReactiveVar) is also used to cause the helper to re-run (independently of any cursor changes). A by-product of that re-run is to change the cursor by means of its sort property. Hence the re-render.