Class DataPage Documentation

Description

Inspired by Perl module Data::Page

The main concept is that you pass in the number of total entries, the number of entries per page, and the current page number. You can then call methods to find out how many pages of information there are, and what number the first and last entries on the current page really are.

construct

var datapage = new DataPage(total_entries, entries_per_page, current_page, total_numbers)

    var datapage = new DataPage(80, 10, 1, 6);

attributes

total_entries get or sets the total number of entries

    datapage.total_entries = 80; // default 0

entries_per_page gets or sets the total number of entries per page

    datapage.entries_per_page = 20; // default 10

current_page gets or sets the current page number

    datapage.current_page = 2; // default 1

total_numbers gets or sets the total numeration

    datapage.total_numbers = 6; // default 10

methods

entries_on_this_page This methods returns the number of entries on the current page

    document.write(datapage.entries_on_this_page());

first_page This method returns the first page. This is put in for reasons of symmetry with last_page, as it always returns 1

    document.write(datapage.first_page());

last_page This method returns the total number of pages of information

    document.write(datapage.last_page());

first This method returns the number of the first entry on the current page

    document.write(datapage.first());

last This method returns the number of the last entry on the current page

    document.write(datapage.last());

previous_page This method returns the previous page number, if one exists. Otherwise it returns undefined

    document.write(datapage.previous_page());

next_page This method returns the next page number, if one exists. Otherwise it returns undefined

    document.write(datapage.next_page());

skipped This method returns the next page number, if one exists. Otherwise it returns undefined

    SELECT * FROM table ORDER BY rec_date LIMIT datapage.skipped, datapage.entries_per_page

change_entries_per_page This method changes the number of entries per page and the current page number such that the first item on the current page will be present on the new page.

    datapage.change_entries_per_page(20);

start_number This method return first numeration and end_number This method return last numeration

    for(var i=datapage.start_number(); i<=datapage.end_number(); i++){
        if(i == datapage.current_page()){
            document.write(i);
        }else{
            document.write("<a href='?page="+i+"'>"+i+"</a>");
        }
    }

array_numbers This method return total numeration in array

    for(row in datapage.array_numbers()){
        if(row == datapage.current_page()){
            document.write(row);
        }else{
            document.write("<a href='?page="+row+"'>"+row+"</a>");
        }
    }

Author

Lucas Tiago de Moraes

Support

lucastiagodemoraes@gmail.com