Javascript/Projects/Pager

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Introduction

This pager is meant to be a generic object. It takes an ordered set of data (from an Array-like object) and figures out how many pages there are and will give back a page from it.

Usage

var pager = Pager([1,2,3], 2);
var page = 5;
var pages = pager.page;
var total_items = pager.data.length;
var result = pager.get_page(page);
var items_on_page = result.page;
var from = result.from;
var to = result.to;

Code

License

I'd like people to include this in their code, but I don't want people to make a change to it and not share it. That's why it's GPL. I understand why people don't like this license. Honestly, if you're not contributing code that will always be free and that encourages other people to contribute such code, then you aren't helping with the solution.

Contact

This code is simple enough you should be able to understand it.