3 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
4 * Note that most of the paging logic is done in
5 * DataTable.ext.oPagination
9 * Generate the node required for default pagination
10 * @param {object} oSettings dataTables settings object
11 * @returns {node} Pagination feature node
12 * @memberof DataTable#oApi
14 function _fnFeatureHtmlPaginate ( oSettings )
16 if ( oSettings.oScroll.bInfinite )
21 var nPaginate = document.createElement( 'div' );
22 nPaginate.className = oSettings.oClasses.sPaging+oSettings.sPaginationType;
24 DataTable.ext.oPagination[ oSettings.sPaginationType ].fnInit( oSettings, nPaginate,
25 function( oSettings ) {
26 _fnCalculateEnd( oSettings );
31 /* Add a draw callback for the pagination on first instance, to update the paging display */
32 if ( !oSettings.aanFeatures.p )
34 oSettings.aoDrawCallback.push( {
35 "fn": function( oSettings ) {
36 DataTable.ext.oPagination[ oSettings.sPaginationType ].fnUpdate( oSettings, function( oSettings ) {
37 _fnCalculateEnd( oSettings );
49 * Alter the display settings to change the page
50 * @param {object} oSettings dataTables settings object
51 * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
52 * or page number to jump to (integer)
53 * @returns {bool} true page has changed, false - no change (no effect) eg 'first' on page 1
54 * @memberof DataTable#oApi
56 function _fnPageChange ( oSettings, mAction )
58 var iOldStart = oSettings._iDisplayStart;
60 if ( typeof mAction === "number" )
62 oSettings._iDisplayStart = mAction * oSettings._iDisplayLength;
63 if ( oSettings._iDisplayStart > oSettings.fnRecordsDisplay() )
65 oSettings._iDisplayStart = 0;
68 else if ( mAction == "first" )
70 oSettings._iDisplayStart = 0;
72 else if ( mAction == "previous" )
74 oSettings._iDisplayStart = oSettings._iDisplayLength>=0 ?
75 oSettings._iDisplayStart - oSettings._iDisplayLength :
78 /* Correct for under-run */
79 if ( oSettings._iDisplayStart < 0 )
81 oSettings._iDisplayStart = 0;
84 else if ( mAction == "next" )
86 if ( oSettings._iDisplayLength >= 0 )
88 /* Make sure we are not over running the display array */
89 if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
91 oSettings._iDisplayStart += oSettings._iDisplayLength;
96 oSettings._iDisplayStart = 0;
99 else if ( mAction == "last" )
101 if ( oSettings._iDisplayLength >= 0 )
103 var iPages = parseInt( (oSettings.fnRecordsDisplay()-1) / oSettings._iDisplayLength, 10 ) + 1;
104 oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength;
108 oSettings._iDisplayStart = 0;
113 _fnLog( oSettings, 0, "Unknown paging action: "+mAction );
115 $(oSettings.oInstance).trigger('page', oSettings);
117 return iOldStart != oSettings._iDisplayStart;