reactive-table
reactive-table copied to clipboard
Tip for transforming Id into element value
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(); } },
],
};
},
Thanks!
Another solution is to use 'tmpl'
But I struggled a lot as well to find out how to manage this :)