reactive-table icon indicating copy to clipboard operation
reactive-table copied to clipboard

Tip for transforming Id into element value

Open aessig opened this issue 8 years ago • 2 comments

This is just a tip for people like me who struggle to display a value associated with an ID in a reactive-table. The best solution I found was to use meteor-collection-helpers. Here is an example how to users it (took from collection-helpers readme):

Books = new Mongo.Collection('books');
Authors = new Mongo.Collection('authors');

Books.helpers({
  author() {
    return Authors.findOne(this.authorId);
  }
});

Authors.helpers({
  fullName() {
    return '${this.firstName} ${this.lastName}';
  },
});

The idea is simple, once you have setup the helpers to get the value you want. You just have to call it from reactive-table settings.

settings: function () {
  return {
    collection: Books,
    rowsPerPage: 10,
    showFilter: true,
    fields: [
      { key: "authorId", label: "Author", fn: function (value, object, key) {return object.author().fullName();  }  },
    ],
  };
},

aessig avatar Sep 04 '16 09:09 aessig

Thanks!

aslagle avatar Sep 05 '16 22:09 aslagle

Another solution is to use 'tmpl'

But I struggled a lot as well to find out how to manage this :)

guillim avatar Dec 31 '16 20:12 guillim