jonlil / mongoose-paginate

mongoose-paginate
MIT License
26 stars 1 forks source link

How can I tell if the use has return the beginner of collection pages? #2

Closed yi closed 9 years ago

yi commented 10 years ago

When I use model.execPagination(), the result will always contain before and after. So I can I tell if the user has reached the beginner (or the end) of the whole collection?

Following is my code, currently it loops from the begining to the end.

# list tickets
# GET /workers
exports.index = (req, res, next)->

  Worker.paginate(req, '_id').execPagination (err, result)->
    return next err if err?
    return next() unless result?
    console.dir result

    res.render 'workers/index', result
    return
  return
yi commented 10 years ago

Hi, I just realized this plugin is pefect for endless scrolling.

So I close this ticket for now.

jonlil commented 10 years ago

Hi, in my mind the only way to know this is to make another query. I think it's a good feature but I don't think its a good idea to make it without letting the implementor decide to query their db one more time. @yi, what do you think?

yi commented 10 years ago

Hi Jonas,

Just a quick thought:

From my use of your pagination plugin, I found it could be ideally server two different scenarioes:

a: user brows the data set page by page

b: user scrolls the data set within a fixed-sized window (I personally prefer this experience on large volumn of data, because its better for searching, performance, caching and implementation)

So, how about provide one method for each scenario?

Let's say:

Model.paginate() works for pagination purpose,

and

Model.scroll() works for scrolling purpose