| 4 |
lars |
1 |
/**
|
|
|
2 |
* This pagination plug-in provides a `dt-tag select` menu with the list of the page
|
|
|
3 |
* numbers that are available for viewing.
|
|
|
4 |
*
|
|
|
5 |
* @name Select list
|
|
|
6 |
* @summary Show a `dt-tag select` list of pages the user can pick from.
|
|
|
7 |
* @author _jneilliii_
|
|
|
8 |
*
|
|
|
9 |
* @example
|
|
|
10 |
* $(document).ready(function() {
|
|
|
11 |
* $('#example').dataTable( {
|
|
|
12 |
* "sPaginationType": "listbox"
|
|
|
13 |
* } );
|
|
|
14 |
* } );
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
$.fn.dataTableExt.oPagination.listbox = {
|
|
|
18 |
/*
|
|
|
19 |
* Function: oPagination.listbox.fnInit
|
|
|
20 |
* Purpose: Initalise dom elements required for pagination with listbox input
|
|
|
21 |
* Returns: -
|
|
|
22 |
* Inputs: object:oSettings - dataTables settings object
|
|
|
23 |
* node:nPaging - the DIV which contains this pagination control
|
|
|
24 |
* function:fnCallbackDraw - draw function which must be called on update
|
|
|
25 |
*/
|
|
|
26 |
"fnInit": function (oSettings, nPaging, fnCallbackDraw) {
|
|
|
27 |
var nInput = document.createElement('select');
|
|
|
28 |
var nPage = document.createElement('span');
|
|
|
29 |
var nOf = document.createElement('span');
|
|
|
30 |
nOf.className = "paginate_of";
|
|
|
31 |
nPage.className = "paginate_page";
|
|
|
32 |
if (oSettings.sTableId !== '') {
|
|
|
33 |
nPaging.setAttribute('id', oSettings.sTableId + '_paginate');
|
|
|
34 |
}
|
|
|
35 |
nInput.style.display = "inline";
|
|
|
36 |
nPage.innerHTML = "Page ";
|
|
|
37 |
nPaging.appendChild(nPage);
|
|
|
38 |
nPaging.appendChild(nInput);
|
|
|
39 |
nPaging.appendChild(nOf);
|
|
|
40 |
$(nInput).change(function (e) { // Set DataTables page property and redraw the grid on listbox change event.
|
|
|
41 |
window.scroll(0,0); //scroll to top of page
|
|
|
42 |
if (this.value === "" || this.value.match(/[^0-9]/)) { /* Nothing entered or non-numeric character */
|
|
|
43 |
return;
|
|
|
44 |
}
|
|
|
45 |
var iNewStart = oSettings._iDisplayLength * (this.value - 1);
|
|
|
46 |
if (iNewStart > oSettings.fnRecordsDisplay()) { /* Display overrun */
|
|
|
47 |
oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
|
|
|
48 |
fnCallbackDraw(oSettings);
|
|
|
49 |
return;
|
|
|
50 |
}
|
|
|
51 |
oSettings._iDisplayStart = iNewStart;
|
|
|
52 |
fnCallbackDraw(oSettings);
|
|
|
53 |
}); /* Take the brutal approach to cancelling text selection */
|
|
|
54 |
$('span', nPaging).bind('mousedown', function () {
|
|
|
55 |
return false;
|
|
|
56 |
});
|
|
|
57 |
$('span', nPaging).bind('selectstart', function () {
|
|
|
58 |
return false;
|
|
|
59 |
});
|
|
|
60 |
},
|
|
|
61 |
|
|
|
62 |
/*
|
|
|
63 |
* Function: oPagination.listbox.fnUpdate
|
|
|
64 |
* Purpose: Update the listbox element
|
|
|
65 |
* Returns: -
|
|
|
66 |
* Inputs: object:oSettings - dataTables settings object
|
|
|
67 |
* function:fnCallbackDraw - draw function which must be called on update
|
|
|
68 |
*/
|
|
|
69 |
"fnUpdate": function (oSettings, fnCallbackDraw) {
|
|
|
70 |
if (!oSettings.aanFeatures.p) {
|
|
|
71 |
return;
|
|
|
72 |
}
|
|
|
73 |
var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
|
|
|
74 |
var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; /* Loop over each instance of the pager */
|
|
|
75 |
var an = oSettings.aanFeatures.p;
|
|
|
76 |
for (var i = 0, iLen = an.length; i < iLen; i++) {
|
|
|
77 |
var spans = an[i].getElementsByTagName('span');
|
|
|
78 |
var inputs = an[i].getElementsByTagName('select');
|
|
|
79 |
var elSel = inputs[0];
|
|
|
80 |
if(elSel.options.length != iPages) {
|
|
|
81 |
elSel.options.length = 0; //clear the listbox contents
|
|
|
82 |
for (var j = 0; j < iPages; j++) { //add the pages
|
|
|
83 |
var oOption = document.createElement('option');
|
|
|
84 |
oOption.text = j + 1;
|
|
|
85 |
oOption.value = j + 1;
|
|
|
86 |
try {
|
|
|
87 |
elSel.add(oOption, null); // standards compliant; doesn't work in IE
|
|
|
88 |
} catch (ex) {
|
|
|
89 |
elSel.add(oOption); // IE only
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
spans[1].innerHTML = " of " + iPages;
|
|
|
93 |
}
|
|
|
94 |
elSel.value = iCurrentPage;
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
};
|