meteor-tabular icon indicating copy to clipboard operation
meteor-tabular copied to clipboard

Update 'selector' and re-draw table

Open josegilmon opened this issue 9 years ago • 7 comments

Hi all!!

I'm facing a problem which I don't know how to solve and I hope you can help me.

I've created a table with the 'selector' option, which filters the items depending on a concrete value (i.e. a project Id).

TabularTables.Actions = new Tabular.Table({
  // other properties...
  selector: function( userId ) {
    // projectId is retrieved from the user
    return { project: projectId };
  }
});

As I navigate through the application, I may change that value and in that case, I want to refresh the data (as the selector has changed) and redraw the table with the new items, but I don't know if there is a way to update that selector 'on the fly'. As there are thousand of elements and I need them to be filtered in server-side, I can't use a template helper.

Do you know any solution for this kind of problem??

Thanks on advance!!

josegilmon avatar Mar 15 '16 11:03 josegilmon

I've encountered the same issue.

Is there any progress or workaround on this? :)

rudza avatar May 16 '16 19:05 rudza

I'm having a similar issue - I can only update the selector once. After that, it no longer redraws the table.

william-bratches avatar May 27 '16 17:05 william-bratches

Looking inside the code, it seems that tabular's autoruns are not being rerun when the selector is updated. To solve for this, I put a template.currentData() inside each of the autoruns that exist in tabular.js.

This works for my purposes, but I'm not sure if there are adverse side effects of this, and am thus hesitant to create a pull request.

william-bratches avatar May 31 '16 16:05 william-bratches

If the selector is changing, it seems like it should be a reactive selector on the client. All of the querying still happens on the server regardless of where the selector comes from.

aldeed avatar Oct 30 '16 22:10 aldeed

If your selector is an object stored in a reactiveVar , you need to clone it after .get() before changing values.

.get() gives you a reference to the object, so modifying it directly before the .set() will prevent reactivity because you will end up with the same object.

This discussion is helpful : https://github.com/meteor/meteor/issues/4414#issuecomment-222032868

nabiltntn avatar Jul 24 '18 09:07 nabiltntn

Hi use ReactiveDict(), and not ReactiveVar(). This is working correctly!

WemersonPD avatar Jun 01 '21 22:06 WemersonPD

I'm noticing the server doesn't notice any changes from a ReactiveDict if all keys remain the same. Is there a solution to this?

I.e. {foo:'foo'} to {foo:'bar'} should reactively trigger the server to re-query but it does not.

smohantyCME avatar Mar 16 '22 16:03 smohantyCME