meteor-admin icon indicating copy to clipboard operation
meteor-admin copied to clipboard

How can I add column to admin users table?

Open epaminond opened this issue 10 years ago • 17 comments

Is there an easy way to add a column to /admin/Users template? It seems AdminConfig Users collection doesn't override default options.

epaminond avatar Dec 27 '14 09:12 epaminond

Create a new User Schema and attach the field you desire. When you restart the application, the field should be available.

rwatts3 avatar Dec 27 '14 19:12 rwatts3

@rwatts3 I've tried it. Can you provide a code snippet with example of configuration? I'm trying to show a field from user's profile on users list table.

epaminond avatar Dec 27 '14 20:12 epaminond

That's actually more complex as there is custom template for users collection which is not using schema. You would have to customize adminPagesTable and adminPagesUserItem templates.

mpowaga avatar Jan 01 '15 18:01 mpowaga

Got same needs. Users table columns will be customisable in a future version ?

Thanks. Pascoual

pascoual avatar Feb 06 '15 22:02 pascoual

Add another vote for being able to customize the user table columns.

jay-depot avatar Jun 30 '15 22:06 jay-depot

plus 1 for custom user templates and extending user schema.

Ajaxsoap avatar Jul 15 '15 17:07 Ajaxsoap

Would love to see the ability to extend the user templates and columns.

etcook avatar Aug 07 '15 19:08 etcook

I was hoping this is available already

morrismukiri avatar Aug 30 '15 23:08 morrismukiri

So we still cant customize the user templates?

smilansky avatar Jan 19 '16 21:01 smilansky

+1

bulleric avatar Jan 27 '16 22:01 bulleric

+1

HelloYie avatar Feb 15 '16 09:02 HelloYie

+1

HazemKhaled avatar Mar 20 '16 14:03 HazemKhaled

+1

mvcdev avatar Sep 26 '16 08:09 mvcdev

+1

jc2 avatar Oct 25 '16 19:10 jc2

@mpowaga I can't find those two templates in the code (adminPagesTable and adminPagesUserItem) and this has no effect:

<template name="adminPagesTable">
  Hello world
</template>
<template name="adminPagesUserItem">
  Goodnight moon
</template>

Did the names of these templates change?

Update: code: https://github.com/yogiben/meteor-admin/blob/4b20c82aa39addcc2cc5cb9f93b835c56a31e60d/lib/both/startup.coffee#L172

MichaelJCole avatar Dec 28 '16 17:12 MichaelJCole

Ok, this is hacky, but here's how to do it:

AdminConfig = {
 // Define your admin config here.
};

// Hack for admin user's table: https://github.com/yogiben/meteor-admin/blob/4b20c82aa39addcc2cc5cb9f93b835c56a31e60d/lib/both/startup.coffee#L172
import Tabular from 'meteor/aldeed:tabular';

// Don't forget Meteor.startup, and change Tabular.Table to  Tabular.Tabular.Table
Meteor.startup(()=>{

  var adminDelButton, adminEditButton, adminEditDelButtons, adminTablesDom;

  adminTablesDom = '<"box"<"box-header"<"box-toolbar"<"pull-left"<lf>><"pull-right"p>>><"box-body"t>><r>';

  adminEditButton = {
    data: '_id',
    title: 'Edit',
    createdCell: function(node, cellData, rowData) {
      return $(node).html(Blaze.toHTMLWithData(Template.adminEditBtn, {
        _id: cellData
      }));
    },
    width: '40px',
    orderable: false
  };

  adminDelButton = {
    data: '_id',
    title: 'Delete',
    createdCell: function(node, cellData, rowData) {
      return $(node).html(Blaze.toHTMLWithData(Template.adminDeleteBtn, {
        _id: cellData
      }));
    },
    width: '40px',
    orderable: false
  };

  adminEditDelButtons = [adminEditButton, adminDelButton];

  //...

  AdminTables.Users = new Tabular.Tabular.Table({
    changeSelector: function(selector, userId) {
      var $or;
      $or = selector['$or'];
      $or && (selector['$or'] = _.map($or, function(exp) {
        var ref;
        if (((ref = exp.emails) != null ? ref['$regex'] : void 0) != null) {
          return {
            emails: {
              $elemMatch: {
                address: exp.emails
              }
            }
          };
        } else {
          return exp;
        }
      }));
      return selector;
    },
    name: 'Users',
    collection: Meteor.users,
    columns: _.union([
      {
        data: '_id',
        title: 'Hello',
        createdCell: function(node, cellData, rowData) {
          return $(node).html(Blaze.toHTMLWithData(Template.adminUsersIsAdmin, {
            _id: cellData
          }));
        },
        width: '40px'
      }, {
        data: 'emails',
        title: 'World',
        render: function(value) {
          return value[0].address;
        },
        searchable: true
      }, {
        data: 'emails',
        title: 'Mail',
        createdCell: function(node, cellData, rowData) {
          return $(node).html(Blaze.toHTMLWithData(Template.adminUsersMailBtn, {
            emails: cellData
          }));
        },
        width: '40px'
      }, {
        data: 'createdAt',
        title: 'Joined'
      }
    ], adminEditDelButtons),
    dom: adminTablesDom
  });

});

MichaelJCole avatar Dec 28 '16 17:12 MichaelJCole

+1

Tim-W avatar May 06 '17 09:05 Tim-W