yogiben / meteor-admin

A complete admin dashboard solution
https://atmospherejs.com/yogiben/admin
GNU General Public License v3.0
826 stars 261 forks source link

"No data available in table" for Users with no email associated #293

Open niranjans opened 8 years ago

niranjans commented 8 years ago

This is related to this closed issue.

As some other users have pointed out, if the users without email address (Facebook logins) are removed or if dummy email is filled in, the Users collection shows data. Else, it does not show any data and this is the exception in the console:

Exception from Tracker recompute function:
debug.js:41 TypeError: Cannot read property '0' of undefined
at AdminTables.Users.Tabular.Table.columns._.union.render (startup.coffee:58)
at jquery.dataTables.min.js:15
at Object.b.fnGetData (jquery.dataTables.min.js:9)
at w (jquery.dataTables.min.js:14)
at Ia (jquery.dataTables.min.js:21)
at I (jquery.dataTables.min.js:13)
at ub (jquery.dataTables.min.js:36)
at jquery.dataTables.min.js:33
at Template.tabular.rendered.ajaxOptions.ajax (tabular.js:68)
at qa (jquery.dataTables.min.js:33)

Is there a way to fix this? I am trying to avoid adding dummy emails since that is not a good solution.

tdenovan commented 8 years ago

I think we just need to do a PR to add an if statement to line 195 of meteor-admin/lib/both/startup.coffee to check if any emails are present before returning the address of the first one.

However, if you want a quick fix, I used the following hack (coffee script):

Meteor.startup ->
  # Patch the way yogiben:admin renders users, to fix a bug where they are forced to have emails
  emailColumn = AdminTables.Users.options.columns[1]
  emailColumn.render = (value) ->
    return value[0].address if value? and value[0]?
    "No email"
Kostanos commented 8 years ago

thanks @tdenovan your workaround works well.

For those who need it in JS:

Meteor.startup(function () {
  var emailCol = AdminTables.Users.options.columns[1];
  emailCol.render = function(value){
    return value && value[0] ? value[0].address : 'no email';
  }
});

I placed it in lib/ any file

zhaoyao91 commented 8 years ago

thanks, this is helpful. I hope it can be fixed

paniwani commented 8 years ago

+1