mongoose-datatable
mongoose-datatable copied to clipboard
how to do subquery in formatter
`Model.dataTables({ limit: input.length, skip: input.start, search: { value: req.body.search.value, fields: ['name'] }, sort: orderBy, formatter: function(table) { let permission_html = ""; _.each(table.permission,function(p){ permission_html = permission_html + ""+ p.name +"" })
var count = 0
count = await Admin.countDocuments({'roles':table._id}).exec()
console.log("count")
console.log(count)
return {
actions : '<a href="/admin/role/update/'+table._id+'"><i class="fas fa-edit"></i></a><a data-id="'+table._id+'" href="javascript:void(0)" class="delete_role"><i class="fas fa-trash"></i></a>',
id : table._id,
_id : i++,
name : table.name,
permission : permission_html,
created_at : moment.unix(table.created_at).format("DD-MM-YYYY H:s"),
}
}
}).then(function (table) {
/*console.log("table")
console.log(table)*/
table.draw = table.draw
table.recordsTotal = table.total
table.recordsFiltered = table.total
res.json(table); // table.total, table.data
})`
i want count how much admin hase this role