API for data pagination
Alien::GvaScript::Paginator - API for data pagination
var url = '/app/my/paginated/data'; var mypaginator = new GvaScript.Paginator(url, { list_container : 'list_result_container', links_container : 'pagination_links_container' onSuccess : onSuccessHandler, parameters : {param1: 'val1', param2: 'val2'}, step : 20 }
Paginated data is a set of data that can be divided into differnent pages. It is best described as a list of items that overflow one page and best presented in several pages. The Paginator Object is used in this case to manage retrieval (through AJAX Requests) and handling (through an onSuccess handler). It also will take care of creating the navigation links (first, prev, next, last) and rendering them into provided container. Navigation links are used for an on demand page flipping.
Data will be requested using an HTTP call to a provided URL.
Data Index and Size are decided using INDEX
and STEP
parameters respectively.
It is up to you to make use of these parameters to decide on the items to display.
var paginator = new GvaScript.Paginator( url, {opt1:"val1", opt2:"val2", ...} );
Creates the object that controls pages navigation. Arguments are
Options used to define and customize the Paginator object.
The Paginator object is returned as it might be useful for a programatic navigation of pages.
Available options are:
Element or an id of an HTML Element to render the navigation links into.
required.
Element of an id of an HTML Element that is used to render the result of the pagination. A 'gva-loading' classname is set to this container in the duration of page request. Also ajax timeout and error messages will be displayed in this container.
required.
Number of items to display per page.
This number would be the value of STEP
(HTTP Request Parameter) that is transferred with pagination calls.
optional - defaulted to 20
String indicating the HTTP method to use in the AJAX request for retrieving paginated data.
optional - defaulted to 'post'
String in the syntax of key1=val1&key2=val2, or hash {key1: 'val1', key2: 'val2'} of key/value pairs of parameters to be sent with the HTTP request
optional - defaulted to {}
Function handler of the onSuccess of the AJAX HTTP request to retrieve paginated data.
optional - defaulted to Prototype.emptyFunction
Boolean indicating whether to load first page with the initialization of the Paginator Object.
true
implies lazy loading of the first page - will wait for an explicit call to loadContent
method.
optional - defaulted to false
Number of seconds to wait before aborting the Ajax HTTP Request. Upon abort, an error message will display in the list_container
.
optional - defaulted to 15
Error message to display on timeoutAjax.
optional - defaulted to "Problème de connexion. Réessayer et si le problème persiste, contacter un administrateur."
Returns boolean indicating whether the paginator has more data to display.
Returns boolean indicating whether the paginator has previous data to display.
Returns boolean if successful.
Returns boolean if successful.
Returns boolean if successful.
Returns boolean if successful
Core method that initializes the AJAX HTTP Request to retrieve data and calls the onSuccess handler to dipplay the result.
mypaginator.destroy();
This method will remove all handlers assigned to pagination buttons. Call this method when the paginator element is removed from the DOM.