A mixin to get total count of a model for pagination in a loopback Model.
npm install --save loopback-row-count-mixin
In your server/server.js file add the following line before the boot(app, __dirname); line.
...
var app = module.exports = loopback();
...
// Add Counts Mixin to loopback
require('loopback-row-count-mixin')(app);
boot(app, __dirname, function(err) {
'use strict';
if (err) throw err;
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
To use with your Models add the mixins
attribute to the definition object of your model config.
{
"name": "player",
"properties": {
"name": "string",
"type": "string",
},
"mixins": {
"RowCount": true
}
}
http://0.0.0.0:3000/api/players
will return list of players with field to help for you pagination
{
"count": 2,
"rows": [
{
"id": 1,
"title": "First player",
"type": ""
},
{
"id": 2,
"title": "Second player",
"type": ""
}
]
}
MIT