aslagle / reactive-table

A reactive table designed for Meteor
https://atmospherejs.com/aslagle/reactive-table
Other
328 stars 138 forks source link

Tip for transforming Id into element value #426

Open aessig opened 8 years ago

aessig commented 8 years ago

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();  }  },
    ],
  };
},
aslagle commented 8 years ago

Thanks!

guillim commented 7 years ago

Another solution is to use 'tmpl'

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