I want to create paginated table using sails.js, mongodb and waterline-ORM.
Is there a any specific way to do pagination in sails.js?
I want to create paginated table using sails.js, mongodb and waterline-ORM.
Is there a any specific way to do pagination in sails.js?
http://sailsjs.org/#/documentation/concepts/ORM/Querylanguage.html
If you want the pagination to work asynchronously, its very easy to do with JQUERY
$$.getJSON
and on the serverres.json();
Theres a lot of info in waterline and sails docs.
You could build a functional paginator with built-in
skip
&limit
query parameters for blueprint routes:With this option, you could have dynamically sized page size according to various device sizes - this option you would provide with
limit
, which is basically your page size. Multiply (page size - 1) by current page number - voila you've got yourskip
parameter.As to how to get the number of all items, I haven't found a built-in way to do it, so I've written a little helper middleware (https://github.com/xtrinch/sails-pagination-middleware) to return the total count in the response JSON this way:
All you need to do is install the middleware via npm and add it to your middlewares in
http.js
.If you need a fully functional example, I've also got an example to-do app with this sort of pagination on github: https://github.com/xtrinch/vue-sails-todo. It's written with vue, but you should get the idea either case.
Note that this answer requires sails 1.x.
I think you can also do it with io:
There is also another way.
if you want to fetch data from the front-end, and have turned blueprint on, you can also try: http://yourDomain.com/ModelName?skip=10&limit=10
Reference: 1.officer site: http://sailsjs.org/#/documentation/reference/blueprint-api/Find.html