I am a bit new to this, I am simply querying data from another server in my nodejs app. And I am not using any local database to save or store anything. I want to paginate my results. But, all examples and code samples that I am seeing using express-paginate are using mongoose or Sequelize. How to paginate without a database ? Please suggest.
Asked
Active
Viewed 366 times
0
-
https://stackoverflow.com/questions/42761068/paginate-javascript-array – Shankar Shastri Jun 30 '18 at 04:14
1 Answers
1
me make it.
let page = request.payload.page || 1;
let _limit = request.payload.limit || 2;
var _sort = request.payload.sort || 'field';
var _order = request.payload.order || 'asc';
var list = [{object}];
let orderBy = _.orderBy(list, _sort, _order);
let total = orderBy.length,
start = page * _limit - _limit,
end = page * _limit,
pages = list.length / _limit,
data = orderBy.slice(start, end);
return {
total: total,
rows: data,
page: page,
pages: pages
}

Shankar Shastri
- 1,134
- 11
- 18

Tran Hoang Hiep
- 544
- 5
- 12
-
Well, I thought the express-paginate helps with all of this, so if there was some way to use that but not consume data from db. Thanks though. – MithunS Jun 30 '18 at 04:42