1 |
|
2 |
|
3 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
4 |
* Note that most of the paging logic is done in |
5 |
* DataTable.ext.oPagination |
6 |
*/ |
7 |
|
8 |
/** |
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 |
13 |
*/ |
14 |
function _fnFeatureHtmlPaginate ( oSettings ) |
15 |
{ |
16 |
if ( oSettings.oScroll.bInfinite ) |
17 |
{ |
18 |
return null; |
19 |
} |
20 |
|
21 |
var nPaginate = document.createElement( 'div' ); |
22 |
nPaginate.className = oSettings.oClasses.sPaging+oSettings.sPaginationType; |
23 |
|
24 |
DataTable.ext.oPagination[ oSettings.sPaginationType ].fnInit( oSettings, nPaginate, |
25 |
function( oSettings ) { |
26 |
_fnCalculateEnd( oSettings ); |
27 |
_fnDraw( oSettings ); |
28 |
} |
29 |
); |
30 |
|
31 |
/* Add a draw callback for the pagination on first instance, to update the paging display */ |
32 |
if ( !oSettings.aanFeatures.p ) |
33 |
{ |
34 |
oSettings.aoDrawCallback.push( { |
35 |
"fn": function( oSettings ) { |
36 |
DataTable.ext.oPagination[ oSettings.sPaginationType ].fnUpdate( oSettings, function( oSettings ) { |
37 |
_fnCalculateEnd( oSettings ); |
38 |
_fnDraw( oSettings ); |
39 |
} ); |
40 |
}, |
41 |
"sName": "pagination" |
42 |
} ); |
43 |
} |
44 |
return nPaginate; |
45 |
} |
46 |
|
47 |
|
48 |
/** |
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 |
55 |
*/ |
56 |
function _fnPageChange ( oSettings, mAction ) |
57 |
{ |
58 |
var iOldStart = oSettings._iDisplayStart; |
59 |
|
60 |
if ( typeof mAction === "number" ) |
61 |
{ |
62 |
oSettings._iDisplayStart = mAction * oSettings._iDisplayLength; |
63 |
if ( oSettings._iDisplayStart > oSettings.fnRecordsDisplay() ) |
64 |
{ |
65 |
oSettings._iDisplayStart = 0; |
66 |
} |
67 |
} |
68 |
else if ( mAction == "first" ) |
69 |
{ |
70 |
oSettings._iDisplayStart = 0; |
71 |
} |
72 |
else if ( mAction == "previous" ) |
73 |
{ |
74 |
oSettings._iDisplayStart = oSettings._iDisplayLength>=0 ? |
75 |
oSettings._iDisplayStart - oSettings._iDisplayLength : |
76 |
0; |
77 |
|
78 |
/* Correct for under-run */ |
79 |
if ( oSettings._iDisplayStart < 0 ) |
80 |
{ |
81 |
oSettings._iDisplayStart = 0; |
82 |
} |
83 |
} |
84 |
else if ( mAction == "next" ) |
85 |
{ |
86 |
if ( oSettings._iDisplayLength >= 0 ) |
87 |
{ |
88 |
/* Make sure we are not over running the display array */ |
89 |
if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() ) |
90 |
{ |
91 |
oSettings._iDisplayStart += oSettings._iDisplayLength; |
92 |
} |
93 |
} |
94 |
else |
95 |
{ |
96 |
oSettings._iDisplayStart = 0; |
97 |
} |
98 |
} |
99 |
else if ( mAction == "last" ) |
100 |
{ |
101 |
if ( oSettings._iDisplayLength >= 0 ) |
102 |
{ |
103 |
var iPages = parseInt( (oSettings.fnRecordsDisplay()-1) / oSettings._iDisplayLength, 10 ) + 1; |
104 |
oSettings._iDisplayStart = (iPages-1) * oSettings._iDisplayLength; |
105 |
} |
106 |
else |
107 |
{ |
108 |
oSettings._iDisplayStart = 0; |
109 |
} |
110 |
} |
111 |
else |
112 |
{ |
113 |
_fnLog( oSettings, 0, "Unknown paging action: "+mAction ); |
114 |
} |
115 |
$(oSettings.oInstance).trigger('page', oSettings); |
116 |
|
117 |
return iOldStart != oSettings._iDisplayStart; |
118 |
} |