Is there a way to do select query and count_all query via single method? For pagination purposes we need to know total number of items so we can calculate and show number of pages.
getLength: function(req, res) {
Posts.find({}).exec(function(err, items){
return items.length;
});
}
Check out Sails.Js - How I do pagination in sails.Js for pagination in Waterline.
To get the total number of items, you can use:
Post.count().exec(function (err, nbOfInstances) {
if(err) return res.negociate(err);
return res.ok(nbOfInstances);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With