From 48930f65dc94f1ff159325619d631dfd82a7cae4 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Wed, 9 Jul 2014 11:51:13 +0100 Subject: [PATCH] Dev: Move the jPagination integration into the paging plug-ins --- .../jPaginator/dataTables.jPaginator.js | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 pagination/jPaginator/dataTables.jPaginator.js diff --git a/pagination/jPaginator/dataTables.jPaginator.js b/pagination/jPaginator/dataTables.jPaginator.js new file mode 100644 index 0000000..02d3685 --- /dev/null +++ b/pagination/jPaginator/dataTables.jPaginator.js @@ -0,0 +1,76 @@ +/** + * jQuery DataTables jPaginator plugin v1.0 - integration between DataTables and + * jPaginator + * by Ernani Azevedo + * + * You'll need jQuery DataTables (http://datatables.net/) and jPaginator + * (http://remylab.github.com/jpaginator/) loaded before load this one. + * + * Full description is available here: + * http://www.intellinews.com.br/blog/2012/10/26/jquery-datatables-integration-with-jpaginator-4/ + * + * @license GPL v3.0. + * @example + * // Initialise DataTables with jPaginator paging + * $('#example').dataTable ( { + * 'sPaginationType': 'jPaginator' + * } ); + */ + +// API method to get paging information (Got idea from Twitter Bootstrap plugin): +$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings) +{ + if ( oSettings) + { + return { + "iStart": oSettings._iDisplayStart, + "iEnd": oSettings.fnDisplayEnd (), + "iLength": oSettings._iDisplayLength, + "iTotal": oSettings.fnRecordsTotal (), + "iFilteredTotal": oSettings.fnRecordsDisplay (), + "iPage": Math.ceil ( oSettings._iDisplayStart / oSettings._iDisplayLength), + "iTotalPages": Math.ceil ( oSettings.fnRecordsDisplay () / oSettings._iDisplayLength)}; + } else { + return { + "iStart": 0, + "iEnd": 0, + "iLength": 0, + "iTotal": 0, + "iFilteredTotal": 0, + "iPage": 0, + "iTotalPages": 0 + } + } +}; + +// Extends DataTable to support jPaginator pagination style: +$.fn.dataTableExt.oPagination.jPaginator = { + 'paginator': $('').html ( '
'), + 'fnInit': function ( oSettings, nPaging, fnCallbackDraw) { + $(nPaging).prepend ( this.paginator); + $(this.paginator).jPaginator ( { + selectedPage: 1, + nbPages: 1, + nbVisible: 6, + overBtnLeft: '#o_left', + overBtnRight: '#o_right', + maxBtnLeft: '#m_left', + maxBtnRight: '#m_right', + minSlidesForSlider: 2, + onPageClicked: function ( a, num) { + if ( num - 1 == Math.ceil ( oSettings._iDisplayStart / oSettings._iDisplayLength)) { + return; + } + oSettings._iDisplayStart = ( num - 1) * oSettings._iDisplayLength; + fnCallbackDraw ( oSettings); + } + }).addClass ( 'jPaginator'); + }, + 'fnUpdate': function ( oSettings, fnCallbackDraw) { + if ( ! oSettings.aanFeatures.p) { + return; + } + var oPaging = oSettings.oInstance.fnPagingInfo (); + $(this.paginator).trigger ( 'reset', { nbVisible: 6, selectedPage: oPaging.iPage + 1, nbPages: oPaging.iTotalPages}); + } +};