Reactive-table: Unable to display data for all objects in Meteor.users


#1

Hi,

trying to use reactive-table to display users and to edit. I have two major problems:

  • I am creating the users with Accounts.createUser() method and I have an extra field “profile” (using meteor-roles package). I am defining the table format using the following code:

    Template.adminusers.helpers({
    usersCol: function() {
    return Meteor.users;
    },
    settings: function() {
    return {
    rowsPerPage: 10,
    showFilter: true,
    fields: [{
    key: ‘profile.lastname’,
    label: ‘Last name’
    }, {
    key: ‘profile.firstname’,
    label: ‘First name’
    }, {
    key: ‘roles’,
    label: ‘Role’
    }, {
    key: ‘emails.0.address’,
    label: ‘Email’
    }, {
    key: ‘edit’,
    label: ‘’,
    sortable: false,
    fn: function() {
    var html = ’ Edit’
    return new Spacebars.SafeString(html);
    }
    }]
    };
    }
    });
    The problem is that roles and email are displayed only for the current user. I have no idea why…

  • second problem: I added in the last column a button for Edit which is supposed to open a modal or maybe a different page. How can I link this button to the user for that particular row? So I can create a Template.events method and a modal, etc.


#2

Sorry, I am using meteor-tabular at the moment, but maybe the following hints help:

Ad problem 1:

Quoting the meteor-roles readme:

Meteor.roles is not published by default. Here’s how you would publish it to every client without needing a subscription:

// in server/publish.js
Meteor.publish(null, function (){ 
  return Meteor.roles.find({})
})

Ad problem 2:

Quoting reactive table readme:

Make the event selector be tr, and you’ll have your row object in this:

Template.posts.events({
  'click .reactive-table tr': function (event) {
    // set the blog post we'll display details and news for
    var post = this;
    Session.set('post', post);
  }
});

If you want to use only the button in your last column, you can just assign it a class and then use an event like click .yourClass

Hope that helps


#3

I managed to fix it:

Meteor.publish(“AdminUsers”, function() {
var user = Meteor.users.findOne({
_id: this.userId
});

if (Roles.userIsInRole(user, [SUPERADMIN])) {
    return Meteor.users.find({}, {
        fields: {
            emails: 1,
            profile: 1,
            roles: 1
        }
    });
}

});

I am guessing I need to explicitly mark users fields to be published. Which is more secure, true…