aslagle / reactive-table

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

QUESTION: Multiple same ID in Collection how to group into one #407

Closed faavictoriano closed 8 years ago

faavictoriano commented 8 years ago

I have two collections

Group:

_id : groupID3242, GroupName: Group 1

UserGroups

GroupID : groupID3242, User: User1

GroupID : groupID3242, User: User2

How to render in table and group the same GroupID, and return all user in single group. But i still working now, i try to reverse the collection..

aslagle commented 8 years ago

If you're publishing the data already, the simplest option is to use Groups as the collection, and then have a field like

{ key: '_id', 
  label: 'Users', 
  fn: function (groupId) {
    var userGroups = UserGroups.find({groupId: groupId}).fetch();
    // format the users list to display and return it
  }
}
faavictoriano commented 8 years ago

i user this, and solve

 'groupChatTable': function () {
          return {
              collection: Groups,
              rowsPerPage: 10,
              showFilter: true,
              fields: [ { key: 'Name', label: 'Group Name'},
                        { key: '_id', label: 'Members',
                        fn: function(value) { 
                         var usersGroups = UsersGroups.find({GroupFID: value}).fetch();
                         var users = [];
                            _.each(_.values(usersGroups), function(u){
                              var user = Meteor.users.findOne({_id:u.UserFID});
                              users.push(user.username);
                            })
                          return users.length;}
                      },
                      { key: '_id', label: 'Users',
                        fn: function(value) { 
                         var usersGroups = UsersGroups.find({GroupFID: value}).fetch();
                         var users = [];
                            _.each(_.values(usersGroups), function(u){
                              var user = Meteor.users.findOne({_id:u.UserFID});
                              users.push(user.username);
                            })
                          return users;}
                      }]
                };
           }