datatables server side pagination in sails js - pagination

I am new to sails js.In my controller, I am calling an api which gives me a large set of data, approximately 10000 records. I want to show this data in my front end using the datatables, 100 records per page.I don't want all data to be fetched in a single call. Data for each page should be loaded using pagination. Do anyone have any idea? It will be of great help. I am not using the database directly. Everything is via API.

See Sails.Js - How I do pagination in sails.Js:
In sails.js:
Model.find().paginate({page: 2, limit: 10});
Model.find({ where: { name: 'foo' }, limit: 10, skip: 10 });
(Source: https://stackoverflow.com/a/26653121/3340229)
In the frontend, you can add query parameters for this:
http://yourDomain.com/ModelName?skip=10&limit=10
(Source: https://stackoverflow.com/a/27937261/3340229)

Related

How to do pagination in NeptuneDB to achieve high performance

Hi I am now building a website using aws NeptuneDB(Gremlin), NodeJs as Backend and Angular as Frontend. Now I am facing a problem, I want to do pagination on my website because without pagination I may load and display 5000 items one query. I know in MySQL, we can using like
select * from mydb limit 0, 20;
to do pagination.
Can I achieve similar in NeptuneDB(or GraphDB). I investigated for a while and I found this:
How to perform pagination in Gremlin
Refer to the answer of this question, It seems we cannot avoid loading all query results into memory. Does it mean it doesn't make any difference with or without the pagination.
Or can I achieve pagination between Node and Angular(I am just guessing)?
So Any ideas to improve performance?
It seems I can use like
g.V('vertice').out('some_relationship').order().by().range(0,3)
The order can be guarantee through order()
But the problem is:
In pagination, we need to get three parameters: currentPage, PageSize, TotalNumOfItems', currentPage and PageSize is pass from frontend, but how can we get the total number before retrieving items?
my way is just count before retrieve items:
g.V('vertice').out('some_relationship').count()
g.V('vertice').out('some_relationship').order().by().range(0,3)
Will this work?

Get all items on strapi collection

I am using Strapi API on my project, and I would like export my data in CSV file format.
For this, I use a find() request, but the API returns only the first 100 items and I've ~ 2000 items in my database.
Is it possible to remove the limit on my Strapi request ?
For that, you will have to use the _limit filter and use -1 as value.
eg. strapi.query('restaurant).find({_limit: -1});
After that I suggest you export directly from your database it will be easier.

Cloudant DB api supports pagination?

I have an app already using cloudant.synch.query.IndexManager to query the db. But I need pagination. I can see Cloudant supports it by using bookmark, but I can only find doc about using HTTP Post to url Path: /db/_find. the methods in IndexManager don't have bookmark. Is there an cloudant api I can use, instead of doing the http post?
My app is Android and iOS app that uses IBM Bluemix MobileFirst service as the back end. And I'm using bms_samples_android_bluelist (https://github.com/ibm-bluemix-mobile-services/bms-samples-android-bluelist)as an example.
Use Skip and Limit for paging.
I got this from Cloudand Synch doc https://github.com/cloudant/sync-android/blob/master/doc/query.md
Skip and limit
Skip and limit allow retrieving subsets of the results. Amongst other things, this is useful in pagination.
skip skips over a number of results from the result set.
limit defines the maximum number of results to return for the query.
To display the twenty-first to thirtieth results:
QueryResult result = im.find(query, 20, 10, fields, null);
To disable:
skip, pass 0 as the skip argument.
limit, pass 0 as the limit argument.
Yep! Cloudant's native mobile libraries for Android and iOS are dubbed "Cloudant Synch." Most of the resources there are compiled on this page: https://cloudant.com/cloudant-sync-resources/

Mongoose, AngularJS, NodeJS

I am using a MongoDB database.
For the front AngularJS.
Also, I am using Mongoose.
I have:
app.get("/images", function(req, res) {
mongoose.model('Image').find(function (err, images) {
res.send(images);
});
});
app.listen(3000);
It works fine when I go to: http://localhost:3000/images
then:
<div ng-repeat="photo in photos">
<!-- My Data List -->
<h3>{{photo.name}}</h3>
</div>
Until here, everything is fine.
BUT I will have like thousand and thousand data to display.
So I will need something like "infinite scroll" for the front and also I will need to limit the API http://localhost:3000/images with query range or pagination ???
How I can proceed to do something with lots of data?
Thanks!
You likely don't want to load all data at once if it is a huge amount.
First I would do something like this limit the number of entries you get for each request.
app.get("/images", function(req, res) {
var query = mongoose.model('Image').find({})
.limit(req.query.numberOfItems)
.skip(req.query.index)
query.exec(function (err, images) {
res.send(images);
});
});
app.listen(3000);
On the client you should then decide to dynamically load more data once you need it.
This depends a little bit on what you want the user experience to be e.g have different pages and you load more data once you open the next page or if the user scrolls down further etc.
Use server side pagination in mongoose using mongoose-paginate and limit your query output. Same way to include pagination in angular use angular-ui pagination. If you want to use the infinite scroll then in angular use ngInfiniteScroll.
Hope this helps.
You can use the mongoose Query API to specify conditions on which to search: http://mongoosejs.com/docs/queries.html
You can use where() to specify you pagination criteria, e.g., where({id: {$gt: page}}) (assuming you are using some kind of auto-incrementing id) and limit() to specify your page size, e.g., limit(10).
Each time you query the server for an additional page, you will need to supply the criteria in your URL: /images?page=1. This criteria should be incremented by 10 each time you fetch a page.
The criteria can be anything that represents a sequential ordering of your data, whether an ID, or a timestamp, or some other arbitrary value.
To limit the data in mongoose:
mongoose.model('Image').limit(10).exec(function(err, images){
// get the images....
}); // this will only return 10 images
While in angular you can use limitTo filter:
<div ng-repeat="photo in photos | limitTo: 10 ">
<!-- My Data List -->
<h3>{{photo.name}}</h3>
</div>
Now from here you can learn how to paginate or infinit scroll. (There are various tuts on this topic on the web)

ember.js rest api with pagination

At the moment I'm pointless how do achieve pagination with ember-data. I found out, that i can return 'meta' property in response and ember-data does not throw an error. But I just don't know how to access it, nor what is intended purpose of this property.
The few examples on internet assume that i have whole collection already loaded to ember, or they do little trick and do infinite scroll, which does'nt require information about page count.
I think that loading all records it's ok if I would have < 1k of them, but sometimes I'll be dealing with massive amounts of data (let's say apache logs). What then?
So basically I'm at the point in which I would like to use ember and ember-data to build my first real-life application, but I just think that it is not a good idea.
Ok, so anybody has any idea how to solve this basic, yet complicated, problem? :)
Ok, so here are some ideas to get you started.
First, you have to start with a route and take an page number as a dynamic parameter.
this.resource('posts', { path: '/posts/:page' };
Then as I have no experience with Silex, you need to support some kind of server side parameters that could be used for pagination. For example offset and limit where first means how many records you want to skip and second how many record you want in select from there. Ideally you should implement them as query parameters like ?offset=0&limit=10.
Then you just implement your table route as follows:
App.TableRoute = Ember.Route.extend({
model: function (params) {
return App.Post.find({ offset: (params.page - 1) * 10, limit: 10 });
}
});
You can then start doing some more magic and create your items per page parameter or validate the page number by fetching number of all records in advance.

Resources