### HTML containers for pagination Source: https://github.com/superraytin/paginationjs/blob/master/README.md Placeholder elements for data and pagination containers used in all examples. ```html
``` -------------------------------- ### Pagination with Underscore templating Source: https://github.com/superraytin/paginationjs/blob/master/README.md Uses _.template on the template-demo script and passes data to render the list. ```javascript $('#pagination-container').pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], callback: function(data, pagination) { var html = _.template($('#template-demo').html(), { data: data }); $('#data-container').html(html); } }) ``` -------------------------------- ### Pagination with Handlebars templating Source: https://github.com/superraytin/paginationjs/blob/master/README.md Uses Handlebars.compile on the template-demo script and passes data to render the list. ```javascript $('#pagination-container').pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], callback: function(data, pagination) { var html = Handlebars.compile($('#template-demo').html(), { data: data }); $('#data-container').html(html); } }) ``` -------------------------------- ### Full configuration example with dataSource, ajax, and callbacks Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/configuration.md Shows a complete pagination setup with data source, AJAX options, result formatting, error handling, header/footer templates, and a theme class. The header uses template variables like <%= rangeStart %> and <%= totalNumber %>. ```javascript $('#pagination-container').pagination({ dataSource: '/api/items', totalNumberLocator: function(response) { return response.meta.total; }, locator: 'data.items', alias: { pageNumber: 'pageNum', pageSize: 'limit' }, ajax: { type: 'GET', dataType: 'json', pageNumberStartWithZero: true, beforeSend: function() { showLoading(); } }, formatResult: function(data) { return decorate(data); }, formatAjaxError: function(jqXHR, textStatus, errorThrown) { console.error(errorThrown); }, onError: function(errorThrown, errorType) { console.error(errorType, errorThrown); }, header: '
Showing <%= rangeStart %>–<%= rangeEnd %> of <%= totalNumber %>
', footer: '
End
', className: 'paginationjs-theme-blue paginationjs-small', callback: function(data, pagination) { render(data); } }); ``` -------------------------------- ### Basic pagination initialization Source: https://github.com/superraytin/paginationjs/blob/master/README.md Initializes pagination on #pagination-container with a dataSource array and a callback that renders data into #data-container. ```javascript $('#pagination-container').pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], callback: function(data, pagination) { // template method of yourself var html = template(data); $('#data-container').html(html); } }) ``` -------------------------------- ### Simple templating function Source: https://github.com/superraytin/paginationjs/blob/master/README.md Minimal rendering method that builds an HTML list from the data array. ```javascript function simpleTemplating(data) { var html = ''; return html; } ``` -------------------------------- ### Pagination with Page Size Changer and Navigator (demo2) Source: https://github.com/superraytin/paginationjs/blob/master/examples/pagination.html Configures pagination with pageSize 10, a go input and button, a navigator, and a size changer. The formatNavigator template displays the range and total item count. Includes the same beforeInit and beforePageOnClick hooks as the demo1 example. ```javascript $(function() { (function(name) { var container = $('#pagination-' + name); if (!container.length) return; var sources = function () { var result = []; for (var i = 1; i < 196; i++) { result.push(i); } return result; }(); var options = { dataSource: sources, pageSize: 10, showGoInput: true, showGoButton: true, showNavigator: true, showSizeChanger: true, formatNavigator: '<%= rangeStart %>-<%= rangeEnd %> of <%= totalNumber %> items', callback: function (response, pagination) { window.console && console.log(response, pagination); var dataHtml = ''; container.prev().html(dataHtml); } }; //$.pagination(container, options); container.addHook('beforeInit', function () { window.console && console.log('beforeInit...'); }); container.pagination(options); container.addHook('beforePageOnClick', function () { window.console && console.log('beforePageOnClick...'); //return false }); })('demo2'); }) ``` -------------------------------- ### dataSource URL with query parameters Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Example of the URL after appending `pageNumber` and `pageSize` parameters. These names can be customized via `alias`. ```plaintext /test.json?pageNumber=2&pageSize=10 ``` -------------------------------- ### Pagination with simpleTemplating callback Source: https://github.com/superraytin/paginationjs/blob/master/README.md Calls the simpleTemplating function inside the pagination callback to render data. ```javascript $('#pagination-container').pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, ... , 195], callback: function(data, pagination) { var html = simpleTemplating(data); $('#data-container').html(html); } }) ``` -------------------------------- ### Handlebars template for pagination data Source: https://github.com/superraytin/paginationjs/blob/master/README.md HTML template using Handlebars syntax to render each data item as a list element. ```html ``` -------------------------------- ### Underscore template for pagination data Source: https://github.com/superraytin/paginationjs/blob/master/README.md HTML template using Underscore.js template syntax to iterate over data and output list items. ```html ``` -------------------------------- ### Ajax request with alias parameters Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Example URL after applying the `alias` configuration, showing custom parameter names. ```plaintext /test.json?pageNum=1&limit=10 ``` -------------------------------- ### Basic Pagination with Data Source and Hooks (demo1) Source: https://github.com/superraytin/paginationjs/blob/master/examples/pagination.html Initializes a pagination container with a local array of 195 items. Uses the callback to render items into the preceding element and adds beforeInit and beforePageOnClick hooks that log to the console. The commented $.pagination(container, options) line shows an alternative API call. ```javascript $(function() { (function(name) { var container = $('#pagination-' + name); if (!container.length) return; var sources = function () { var result = []; for (var i = 1; i < 196; i++) { result.push(i); } return result; }(); var options = { dataSource: sources, callback: function (response, pagination) { window.console && console.log(response, pagination); var dataHtml = ''; container.prev().html(dataHtml); } }; //$.pagination(container, options); container.addHook('beforeInit', function () { window.console && console.log('beforeInit...'); }); container.pagination(options); container.addHook('beforePageOnClick', function () { window.console && console.log('beforePageOnClick...'); //return false }); })('demo1'); }) ``` -------------------------------- ### getTotalPage Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Get the total number of pages. ```APIDOC ## getTotalPage ### Description Get the total number of pages. ### Method container.pagination('getTotalPage') ### Parameters None ### Returns - **number** - The total number of pages. ### Example ```js var totalPages = container.pagination('getTotalPage'); ``` ``` -------------------------------- ### getCurrentPageData Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Get the data items of the current page. ```APIDOC ## getCurrentPageData ### Description Get the data items of the current page. ### Method container.pagination('getCurrentPageData') ### Parameters None ### Returns - **array** - The data items of the current page. ### Example ```js var currentPageData = container.pagination('getCurrentPageData'); ``` ``` -------------------------------- ### getCurrentPageNum Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Get the current page number. ```APIDOC ## getCurrentPageNum ### Description Get the current page number. ### Method container.pagination('getCurrentPageNum') ### Parameters None ### Returns - **number** - The current page number. ### Example ```js var currentPage = container.pagination('getCurrentPageNum'); ``` ``` -------------------------------- ### Remote Data Source with Flickr API (demo3) Source: https://github.com/superraytin/paginationjs/blob/master/examples/pagination.html Loads paginated data from the Flickr public feed API using a JSONP URL. Sets pageNumber to 2, totalNumber to 120, and pageSize to 20. The ajax.beforeSend callback displays a loading message, and the callback renders item titles into the preceding element. ```javascript $(function() { (function(name) { var container = $('#pagination-' + name); if (!container.length) return; container.pagination({ dataSource: 'https://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?', locator: 'items', pageNumber: 2, totalNumber: 120, pageSize: 20, ajax: { beforeSend: function() { container.prev().html('Loading data from flickr.com ...'); } }, callback: function(response, pagination) { window.console && console.log(22, response, pagination); var dataHtml = ''; container.prev().html(dataHtml); } }) })('demo3'); }) ``` -------------------------------- ### beforeInit Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before Pagination instance initialized. Return `false` will stop the initialization. ```APIDOC ## beforeInit ### Description Fired before Pagination instance initialized. Return `false` will stop the initialization. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforeInit: function() { // function body } }); // or as a hook container.addHook('beforeInit', function() { // function body }); ``` ``` -------------------------------- ### Initialize pagination and call previous method Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Shows how to initialize Pagination on a container and then call the 'previous' method to go to the previous page. ```javascript var container = $('#example1'); container.pagination({ ... }); container.pagination('previous'); ``` -------------------------------- ### enable Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Enable the pagination. ```APIDOC ## enable ### Description Enable the pagination. ### Method container.pagination('enable') ### Parameters None ### Example ```js container.pagination('enable'); ``` ``` -------------------------------- ### afterInit Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after Pagination initialized. ```APIDOC ## afterInit ### Description Fired after Pagination initialized. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterInit: function() { // function body } }); // or as a hook container.addHook('afterInit', function() { // function body }); ``` ``` -------------------------------- ### next Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Go to the next page. ```APIDOC ## next ### Description Go to the next page. ### Method container.pagination('next') ### Parameters None ### Example ```js container.pagination('next'); ``` ``` -------------------------------- ### beforeDestroy Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/hooks.md Hook fired at start of destroy(). Returning false cancels the destroy. ```APIDOC ## beforeDestroy ### Description Fired at start of `destroy()`. Returning `false` cancels the destroy. ### Fired Start of `destroy()` ### Arguments None ### Return Value Returning `false` cancels the destroy. ### Example ```js $('#example').pagination({ beforeDestroy: function() { // return false to cancel } }); ``` ``` -------------------------------- ### beforeEnable Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/hooks.md Hook fired at start of enable(). Returning false cancels the enable. ```APIDOC ## beforeEnable ### Description Fired at start of `enable()`. Returning `false` cancels the enable. ### Fired Start of `enable()` ### Arguments - `source` (string) - `'async'` or `'sync'` ### Return Value Returning `false` cancels the enable. ### Example ```js $('#example').pagination({ beforeEnable: function(source) { // return false to cancel } }); ``` ``` -------------------------------- ### show Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Display the pagination. ```APIDOC ## show ### Description Display the pagination. ### Method container.pagination('show') ### Parameters None ### Example ```js container.pagination('show'); ``` ``` -------------------------------- ### beforeDisable Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/hooks.md Hook fired at start of disable(). Returning false cancels the disable. ```APIDOC ## beforeDisable ### Description Fired at start of `disable()`. Returning `false` cancels the disable. ### Fired Start of `disable()` ### Arguments - `source` (string) - `'async'` or `'sync'` ### Return Value Returning `false` cancels the disable. ### Example ```js $('#example').pagination({ beforeDisable: function(source) { // return false to cancel } }); ``` ``` -------------------------------- ### previous Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Go to the previous page. ```APIDOC ## previous ### Description Go to the previous page. ### Method container.pagination('previous') ### Parameters None ### Example ```js container.pagination('previous'); ``` ``` -------------------------------- ### beforeRender Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/hooks.md Hook fired at start of render(). Returning false cancels the render. ```APIDOC ## beforeRender ### Description Fired at start of `render()`. Returning `false` cancels the render. ### Fired Start of `render()` ### Arguments - `isForced` (boolean) - `true` on paging, `false` at boot ### Return Value Returning `false` cancels the render. ### Example ```js $('#example').pagination({ beforeRender: function(isForced) { // return false to cancel } }); ``` ``` -------------------------------- ### beforeGoButtonOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before the 'Go' button clicked. ```APIDOC ## beforeGoButtonOnClick ### Description Fired before the 'Go' button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforeGoButtonOnClick: function() { // function body } }); // or as a hook container.addHook('beforeGoButtonOnClick', function() { // function body }); ``` ``` -------------------------------- ### Basic initialization with an array source Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/plugin-method.md Sets up a pagination container with an array data source and a callback that renders each page's items into a data container. Requires the two HTML containers shown. ```html
``` ```javascript $('#pagination-container').pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], pageSize: 5, callback: function(data, pagination) { var html = ''; $('#data-container').html(html); } }); ``` -------------------------------- ### beforePaging Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/hooks.md Hook fired at start of go()'s render(data). Returning false cancels the paging. ```APIDOC ## beforePaging ### Description Fired at start of `go()`'s `render(data)`. Returning `false` cancels the paging. ### Fired Start of `go()`'s `render(data)` ### Arguments - `pageNumber` - The page number being navigated to ### Return Value Returning `false` cancels the paging. ### Example ```js $('#example').pagination({ beforePaging: function(pageNumber) { if (pageNumber === 3) { alert('Page 3 is locked'); return false; // abort this paging } } }); ``` ``` -------------------------------- ### next(callback) Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Moves one page forward and renders. The callback is forwarded to the `go` method. ```APIDOC ## next(callback) ### Description Moves one page forward and renders. On the last page, the corresponding button is disabled/hidden but the method is still callable. ### Method Instance method ### Signature `next: function(callback)` ### Parameters - **callback** (function(data, pagination)) - Optional - Forwarded to `go(...)`. ### Usage Example ```js container.pagination('next', function(data, pagination) { // custom render }); ``` ``` -------------------------------- ### Example: handling async errors with onError and formatAjaxError Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/errors.md Shows a pagination configuration with totalNumberLocator, locator, onError for processing errors, and formatAjaxError for HTTP/transport errors. ```javascript $('#pagination-container').pagination({ dataSource: '/api/items', totalNumberLocator: function(response) { return response.meta.total; }, locator: 'data.items', onError: function(errorThrown, errorType) { // errorType === 'ajaxSuccessHandlerError' console.error('Pagination processing failed:', errorType, errorThrown); showErrorMessage(errorThrown.message); }, formatAjaxError: function(jqXHR, textStatus, errorThrown) { console.error('HTTP/transport error:', textStatus, errorThrown); }, callback: render }); ``` -------------------------------- ### Go to custom page with 'go' method Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Two ways to call the 'go' method: with the method name and page number, or just the page number. ```javascript container.pagination('go', 8) container.pagination(8) ``` -------------------------------- ### onError(errorThrown, errorType) Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md A function to be called if an error is thrown when rendering pagination. The function gets passed two arguments: the error object and the error type. ```APIDOC ## onError(errorThrown, errorType) ### Description A function to be called if an error is thrown when rendering pagination. The function gets passed two arguments: the error object and the error type. ### Parameters - **errorThrown** (object) - Required - The error object. - **errorType** (string) - Required - The error type. Possible values: `ajaxSuccessHandlerError` (error occurred while executing the `success` callback of Ajax). ``` -------------------------------- ### beforeGoInputOnEnter Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before `Enter` pressed on the 'Go' input. ```APIDOC ## beforeGoInputOnEnter ### Description Fired before `Enter` pressed on the 'Go' input. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforeGoInputOnEnter: function() { // function body } }); // or as a hook container.addHook('beforeGoInputOnEnter', function() { // function body }); ``` ``` -------------------------------- ### afterGoButtonOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after the 'Go' button clicked. ```APIDOC ## afterGoButtonOnClick ### Description Fired after the 'Go' button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterGoButtonOnClick: function() { // function body } }); // or as a hook container.addHook('afterGoButtonOnClick', function() { // function body }); ``` ``` -------------------------------- ### Example: registering hooks with addHook Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/hooks.md Shows registering hooks before and after initialization. The beforePageOnClick hook returns false to cancel paging beyond page 10. ```javascript var container = $('#example'); // addHook before initialization also works container.addHook('afterRender', function() { console.log('bar re-rendered'); }); container.pagination({ dataSource: [1, 2, 3, 4, 5], pageSize: 1, callback: renderData }); container.addHook('beforePageOnClick', function(event, pageNumber) { if (pageNumber > 10) return false; // cancel paging beyond page 10 }); ``` -------------------------------- ### Register events as callbacks Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Shows how to register an event (afterRender) as a callback during initialization. ```javascript var container = $('#example1'); container.pagination({ afterRender: function(){ // function body } }); ``` -------------------------------- ### Cancellable hooks example with beforePaging and afterRender Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/hooks.md Shows how to use beforePaging to cancel paging to page 3 and afterRender to log re-renders. The beforePaging hook receives pageNumber; returning false aborts the paging. afterRender logs after each render. ```javascript $('#example').pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pageSize: 2, beforePaging: function(pageNumber) { if (pageNumber === 3) { alert('Page 3 is locked'); return false; // abort this paging } }, afterRender: function() { console.log('pagination bar re-rendered'); } }); ``` -------------------------------- ### beforePaging Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before paging. ```APIDOC ## beforePaging ### Description Fired before paging. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforePaging: function() { // function body } }); // or as a hook container.addHook('beforePaging', function() { // function body }); ``` ``` -------------------------------- ### Usage example: selector string and jQuery object forms Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/static-api.md Shows two ways to call $.pagination: with a CSS selector string or with an existing jQuery object. Both pass options directly to $.fn.pagination(options). The returned container jQuery object is chainable. ```javascript // selector string form var $container = $.pagination('#pagination-container', { dataSource: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pageSize: 3, callback: function(data, pagination) { /* render */ } }); // jQuery object form var $el = $('#pagination-container'); $.pagination($el, { dataSource: [1, 2, 3, 4], pageSize: 2, callback: renderData }); ``` -------------------------------- ### previous(callback) Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Moves one page back and renders. The callback is forwarded to the `go` method. ```APIDOC ## previous(callback) ### Description Moves one page back and renders. On the first page, the corresponding button is disabled/hidden but the method is still callable. ### Method Instance method ### Signature `previous: function(callback)` ### Parameters - **callback** (function(data, pagination)) - Optional - Forwarded to `go(...)`. ### Usage Example ```js container.pagination('previous'); ``` ``` -------------------------------- ### Apply small and blue theme via className option Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Combines the blue theme with the small size class 'paginationjs-small' to render a compact blue pagination. ```javascript className: 'paginationjs-theme-blue paginationjs-small' ``` -------------------------------- ### afterGoInputOnEnter Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after `Enter` pressed on the 'Go' input. ```APIDOC ## afterGoInputOnEnter ### Description Fired after `Enter` pressed on the 'Go' input. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterGoInputOnEnter: function() { // function body } }); // or as a hook container.addHook('afterGoInputOnEnter', function() { // function body }); ``` ``` -------------------------------- ### go Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Go to a custom page. Supports two calling conventions: with or without the method name. Optionally accepts a callback to customize the item's innerHTML of the target page. ```APIDOC ## go ### Description Go to a custom page. Supports two calling conventions: with or without the method name. Optionally accepts a callback to customize the item's innerHTML of the target page. ### Method container.pagination('go', pageNumber, callback) container.pagination(pageNumber) ### Parameters - **pageNumber** (number) - Required - The page number to go to. - **callback** (function) - Optional - A callback function to customize the item's innerHTML of the target page. It receives `data` and `pagination` parameters. ### Example ```js container.pagination('go', 8); container.pagination(8); container.pagination('go', 8, function(data, pagination){ // template method of yourself }); ``` ``` -------------------------------- ### __pagination-show Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Shows the pagination container. Equivalent to calling container.pagination('show'). ```APIDOC ## Event: __pagination-show ### Description Shows the pagination container. Equivalent to calling container.pagination('show'). ### Arguments None. ### Example ```js container.trigger('__pagination-show'); ``` ``` -------------------------------- ### show Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Shows the pagination. Triggered by calling container.pagination('show'). ```APIDOC ## show ### Description Shows the pagination. Triggered by calling container.pagination('show'). ### Method String dispatch ### Endpoint container.pagination('show') ### Parameters None ### Response Returns the jQuery object for chaining. ``` -------------------------------- ### dataSource as Array Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Provides data items directly as an array. All data items are supplied at once. ```plaintext ['1', '2', '3', '4'] ``` -------------------------------- ### Re-initialization with different options Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/plugin-method.md Shows that calling pagination again with a new options object uninstalls the old instance and re-initializes with the new settings. The first call sets up an instance; the second replaces it. ```javascript var container = $('#pagination-container'); container.pagination({ dataSource: [1, 2, 3, 4, 5], pageSize: 2, callback: renderData }); // Passing a new options object uninstalls the old instance and re-initializes: container.pagination({ dataSource: [1, 2, 3, 4, 5, 6, 7, 8], pageSize: 4, callback: renderData }); ``` -------------------------------- ### Constructor Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/plugin-method.md Initializes a pagination instance on a jQuery element. Throws errors for invalid options or missing dependencies. ```APIDOC ## Constructor ### Description Initializes a pagination instance on a jQuery element. Throws errors for invalid options or missing dependencies. ### Method Constructor ### Parameters #### Options (Object) - `dataSource` (Array|Object|Function|String) - Required - The data source for pagination. Must be an array, object, function, or string. - `totalNumber` (Number) - Required when `dataSource` is a string and `totalNumberLocator` is not provided - The total number of items. - `totalNumberLocator` (Function) - Optional - A function to extract total number from a string data source. - `locator` (String) - Required when `dataSource` is an object - A path to the array within the object. - `formatResult` (Function) - Optional - A function to format the result. - `onError` (Function) - Optional - A function to handle errors. ### Throws - `Pagination requires jQuery.` - If `window.jQuery` is undefined at module load. - `plugin conflicted, the name "pagination" has been taken by another jQuery plugin.` - If `$.fn.pagination` is already defined. - `Illegal options` - If `options` is not an object when no instance is initialized. - `"dataSource" is required.` - If `dataSource` is missing. - `"totalNumber" is required.` / `"totalNumber" is incorrect. Expect numberic type` - If `dataSource` is a string and `totalNumberLocator` is not provided. - `"totalNumberLocator" should be a Function.` - If `dataSource` is a string and `totalNumberLocator` is not a function. - `"dataSource" is an Object, please specify a "locator".` - If `dataSource` is an object and `locator` is not provided. - `"formatResult" should be a Function.` - If `formatResult` is not a function. - `"onError" should be a Function.` - If `onError` is not a function. - `Unexpected dataSource type` - If `dataSource` is not an array, object, function, or string. - `dataSource. is undefined.` / `dataSource. should be an Array.` - If the `locator` path resolves to missing or non-array data. ``` -------------------------------- ### beforeNextOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before the 'next' button clicked. ```APIDOC ## beforeNextOnClick ### Description Fired before the 'next' button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforeNextOnClick: function() { // function body } }); // or as a hook container.addHook('beforeNextOnClick', function() { // function body }); ``` ``` -------------------------------- ### afterPaging Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after paging. ```APIDOC ## afterPaging ### Description Fired after paging. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterPaging: function() { // function body } }); // or as a hook container.addHook('afterPaging', function() { // function body }); ``` ``` -------------------------------- ### beforePageOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before page button clicked. ```APIDOC ## beforePageOnClick ### Description Fired before page button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforePageOnClick: function() { // function body } }); // or as a hook container.addHook('beforePageOnClick', function() { // function body }); ``` ``` -------------------------------- ### next Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Moves to the next page. Triggered by calling container.pagination('next'). ```APIDOC ## next ### Description Moves to the next page. Triggered by calling container.pagination('next'). ### Method String dispatch ### Endpoint container.pagination('next') ### Parameters None ### Response Returns the jQuery object for chaining. ``` -------------------------------- ### enable Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Enables the pagination. Triggered by calling container.pagination('enable'). ```APIDOC ## enable ### Description Enables the pagination. Triggered by calling container.pagination('enable'). ### Method String dispatch ### Endpoint container.pagination('enable') ### Parameters None ### Response Returns the jQuery object for chaining. ``` -------------------------------- ### go Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Goes to a specific page number. Triggered by calling container.pagination('go', pageNumber). ```APIDOC ## go ### Description Goes to a specific page number. Triggered by calling container.pagination('go', pageNumber). ### Method String dispatch ### Endpoint container.pagination('go', pageNumber) ### Parameters - **pageNumber** (number) - Required - The page number to go to. ### Response Returns the jQuery object for chaining. ``` -------------------------------- ### afterNextOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after the 'next' button clicked. ```APIDOC ## afterNextOnClick ### Description Fired after the 'next' button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterNextOnClick: function() { // function body } }); // or as a hook container.addHook('afterNextOnClick', function() { // function body }); ``` ``` -------------------------------- ### beforePreviousOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before the 'previous' button clicked. ```APIDOC ## beforePreviousOnClick ### Description Fired before the 'previous' button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforePreviousOnClick: function() { // function body } }); // or as a hook container.addHook('beforePreviousOnClick', function() { // function body }); ``` ``` -------------------------------- ### beforeSizeSelectorChange Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before the size selector changed. ```APIDOC ## beforeSizeSelectorChange ### Description Fired before the size selector changed. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforeSizeSelectorChange: function() { // function body } }); // or as a hook container.addHook('beforeSizeSelectorChange', function() { // function body }); ``` ``` -------------------------------- ### __pagination-enable Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Enables the pagination instance. Equivalent to calling container.pagination('enable'). ```APIDOC ## Event: __pagination-enable ### Description Enables the pagination instance. Equivalent to calling container.pagination('enable'). ### Arguments None. ### Example ```js container.trigger('__pagination-enable'); ``` ``` -------------------------------- ### go(number, callback) Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Navigates to a specific page number. Accepts a numeric page number and an optional callback. In async mode, it triggers an Ajax request; in sync mode, it renders locally. ```APIDOC ## go(number, callback) ### Description Navigates to the specified page number. If the page number is invalid (less than 1, NaN, or greater than total pages), the call is ignored. In async mode, it disables pagination during the request and re-enables it after. ### Method Instance method ### Signature `go: function(number, callback)` ### Parameters - **number** (number | numeric string) - Required - Target page number. Parsed with `parseInt`. Values < 1, NaN, or greater than totalPage are ignored. - **callback** (function(data, pagination)) - Optional - Per-call callback that replaces the instance callback option for this paging. ### Returns `undefined` ### Usage Examples ```js container.pagination('go', 8); container.pagination(8); // numeric shorthand container.pagination('go', 8, function(data, pagination) { // custom render for page 8 only }); ``` ### Hooks Triggers `beforePaging` / `afterPaging`, plus `afterIsFirstPage` (when pageNumber == 1) and `afterIsLastPage` (when pageNumber == getTotalPage()). ``` -------------------------------- ### show() Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Shows the pagination element if it is hidden. No-op if already visible. ```APIDOC ## show() ### Description Shows the pagination element (jQuery `show()` on `model.el`). No-op if already visible. ### Method `show` ### Usage ```js container.pagination('show'); ``` ### Parameters None ### Response Returns `undefined` (via the event path, the chained container). ``` -------------------------------- ### Link pagination.css in HTML header Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Required to load the default pagination styles. Replace {yourAssetsServer} with the actual path to your assets server. ```html ``` -------------------------------- ### previous Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Moves to the previous page. Triggered by calling container.pagination('previous'). ```APIDOC ## previous ### Description Moves to the previous page. Triggered by calling container.pagination('previous'). ### Method String dispatch ### Endpoint container.pagination('previous') ### Parameters None ### Response Returns the jQuery object for chaining. ``` -------------------------------- ### afterPreviousOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after the 'previous' button clicked. ```APIDOC ## afterPreviousOnClick ### Description Fired after the 'previous' button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterPreviousOnClick: function() { // function body } }); // or as a hook container.addHook('afterPreviousOnClick', function() { // function body }); ``` ``` -------------------------------- ### beforeEnable Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before pagination enabled. ```APIDOC ## beforeEnable ### Description Fired before pagination enabled. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforeEnable: function() { // function body } }); // or as a hook container.addHook('beforeEnable', function() { // function body }); ``` ``` -------------------------------- ### __pagination-next Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Triggers navigation to the next page. Equivalent to calling container.pagination('next'). ```APIDOC ## Event: __pagination-next ### Description Triggers navigation to the next page. Equivalent to calling container.pagination('next'). ### Arguments - **done** (function) - Optional - Callback invoked when the navigation completes. ### Example ```js container.trigger('__pagination-next'); ``` ``` -------------------------------- ### dataSource as Object with locator Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Provides data items in an object, requiring `locator: 'data'` to specify the array. ```plaintext { data: ['1', '2', '3', '4'] } ``` -------------------------------- ### alias configuration for pageNumber and pageSize Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Customizes the query parameter names for `pageNumber` and `pageSize` when using Ajax. ```javascript alias: { pageNumber: 'pageNum', pageSize: 'limit' } ``` -------------------------------- ### afterIsFirstPage Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after current page number is the first. ```APIDOC ## afterIsFirstPage ### Description Fired after current page number is the first. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterIsFirstPage: function() { // function body } }); // or as a hook container.addHook('afterIsFirstPage', function() { // function body }); ``` ``` -------------------------------- ### afterEnable Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after pagination enabled. ```APIDOC ## afterEnable ### Description Fired after pagination enabled. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterEnable: function() { // function body } }); // or as a hook container.addHook('afterEnable', function() { // function body }); ``` ``` -------------------------------- ### afterSizeSelectorChange Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after the size selector changed. ```APIDOC ## afterSizeSelectorChange ### Description Fired after the size selector changed. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterSizeSelectorChange: function() { // function body } }); // or as a hook container.addHook('afterSizeSelectorChange', function() { // function body }); ``` ``` -------------------------------- ### pageSize Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Number of data items per page. ```APIDOC ## pageSize ### Description Number of data items per page. ### Type number (default `10`) ``` -------------------------------- ### Go to custom page with callback Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Provides a callback to customize the innerHTML of the target page. Pagination will use this callback instead of the default 'callback' function for this paging. ```javascript container.pagination('go', 8, function(data, pagination){ // template method of yourself }) ``` -------------------------------- ### afterPageOnClick Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired after page button clicked. ```APIDOC ## afterPageOnClick ### Description Fired after page button clicked. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ afterPageOnClick: function() { // function body } }); // or as a hook container.addHook('afterPageOnClick', function() { // function body }); ``` ``` -------------------------------- ### beforeDestroy Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Fired before pagination destroyed. ```APIDOC ## beforeDestroy ### Description Fired before pagination destroyed. ### Event Type Callback or plugin hook ### Parameters None ### Example ```js container.pagination({ beforeDestroy: function() { // function body } }); // or as a hook container.addHook('beforeDestroy', function() { // function body }); ``` ``` -------------------------------- ### Register events as plugin hooks Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Shows how to add a hook (afterRender) after initialization. The hook can be added before Pagination initialized. ```javascript var container = $('#example2'); container.pagination({ dataSource: [1, 2, 3], pageSize: 1 }); container.addHook('afterRender', function(){ // function body }); ``` -------------------------------- ### pageNumber Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Default page number at initialization. ```APIDOC ## pageNumber ### Description Default page number at initialization. ### Type number (default `1`) ``` -------------------------------- ### Apply blue theme via className option Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Sets the pagination theme to blue by adding the class 'paginationjs-theme-blue' to the className option. ```javascript className: 'paginationjs-theme-blue' ``` -------------------------------- ### Apply big and blue theme via className option Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Combines the blue theme with the large size class 'paginationjs-big' to render a large blue pagination. ```javascript className: 'paginationjs-theme-blue paginationjs-big' ``` -------------------------------- ### Plugin constructor signature Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/plugin-method.md Initializes a pagination instance on a container element. Returns the jQuery object for chaining; if options is undefined, it returns this without doing anything. Throws 'Illegal options' if options is not an object when not initialized. ```javascript $.fn.pagination = function(options) { if (typeof options === 'undefined') { return this; } var container = $(this); var attributes = $.extend({}, $.fn[pluginName].defaults, options); // ... parameterChecker(attributes); pagination.initialize(); return this; }; ``` -------------------------------- ### __pagination-previous Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Triggers navigation to the previous page. Equivalent to calling container.pagination('previous'). ```APIDOC ## Event: __pagination-previous ### Description Triggers navigation to the previous page. Equivalent to calling container.pagination('previous'). ### Arguments - **done** (function) - Optional - Callback invoked when the navigation completes. ### Example ```js container.trigger('__pagination-previous'); ``` ``` -------------------------------- ### show() and hide() implementation Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Shows or hides the pagination element using jQuery show()/hide() on model.el. No-op when already in the target visibility state. ```javascript show: function() { var self = this; if (self.model.el.is(':visible')) return; self.model.el.show(); }, hide: function() { var self = this; if (!self.model.el.is(':visible')) return; self.model.el.hide(); } ``` -------------------------------- ### pageRange Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Defines a range of pages that should be displayed around the current page. Set to null to show all pages. ```APIDOC ## pageRange ### Description `pageRange` defines a range of pages that should be display around current page. For example, if current page number is `6` and `pageRange` is set to 2, then pagination bar will be displayed as like this '1 ... 4 5`6`7 8 ... 11 12'. If you want to show all pages, just set it to `null`. ### Type number (default `2`) ``` -------------------------------- ### hide Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Hide the pagination. ```APIDOC ## hide ### Description Hide the pagination. ### Method container.pagination('hide') ### Parameters None ### Example ```js container.pagination('hide'); ``` ``` -------------------------------- ### __pagination-go Source: https://github.com/superraytin/paginationjs/blob/master/_autodocs/api-reference/instance-api.md Triggers navigation to a specific page number on the pagination instance. Equivalent to calling container.pagination('go', pageNumber). ```APIDOC ## Event: __pagination-go ### Description Triggers navigation to a specific page number on the pagination instance. Equivalent to calling container.pagination('go', pageNumber). ### Arguments - **pageNumber** (number) - Required - The page number to navigate to. - **done** (function) - Optional - Callback invoked when the navigation completes. ### Example ```js container.trigger('__pagination-go', 5); ``` ``` -------------------------------- ### callback function signature Source: https://github.com/superraytin/paginationjs/blob/master/docs/en.md Callback invoked on each paging, receives `data` (array of current page items) and `pagination` object. ```javascript callback: function(data, pagination){ ... } ```