Open Obiwarn opened 8 years ago
I would like to do the same thing. I would especially like to add an online status column.
While it's great that meteor admin comes with preconfigured user settings, it would be really nice if these could be overwritten and more configurable.
Found a workaround for now. It's ugly but it works.
Create a lib/users_table.js
Copy in the below code. This is copied from lib/both/startup.coffee
. Editing this will allow you to customize the Users table view precisely.
If you'd rather just customize it using the tableColumns
syntax, I've added code for that as well. Except instead of declaring tableColumns
, declare userColumns
like so
AdminConfig = {
collections: ...
userColumns: [
{label: 'Name', name: 'profile.name'},
],
userSchema: ...
};
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];
var extraColumns = _.map(AdminConfig.userColumns, function(column) {
var createdCell;
if (column.template) {
createdCell = function(node, cellData, rowData) {
$(node).html('');
return Blaze.renderWithData(Template[column.template], {
value: cellData,
doc: rowData
}, node);
};
}
return {
data: column.name,
title: column.label,
createdCell: createdCell
};
});
// default view code, edit this to change the look
AdminTables.Users = new 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: 'Admin',
createdCell: function(node, cellData, rowData) {
return $(node).html(Blaze.toHTMLWithData(Template.adminUsersIsAdmin, {
_id: cellData
}));
},
width: '40px'
}, {
data: 'emails',
title: 'Email',
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'
}
], extraColumns, adminEditDelButtons),
dom: adminTablesDom,
});
Maybe you could refine a bit and submit a PR @merlinpatt?
Here's a less intrusive solution:
Meteor.startup ->
@AdminTables.Users.options.columns.splice(1, 0, title: 'First Name', data: 'profile.firstname')
@AdminTables.Users.options.columns.splice(2, 0, title: 'Last Name', data: 'profile.lastname')
@AdminTables.Users.options.columns.splice(3, 0, title: 'Username', data: 'username')
Further modifications seem to be possible.
How can I add tableColumns to the user table? I need e.g. Name, Language, etc..