FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
jquery.dataTables.select.js
1 
40 $.fn.dataTableExt.oPagination.listbox = {
41  /*
42  * Function: oPagination.listbox.fnInit
43  * Purpose: Initalise dom elements required for pagination with listbox input
44  * Returns: -
45  * Inputs: object:oSettings - dataTables settings object
46  * node:nPaging - the DIV which contains this pagination control
47  * function:fnCallbackDraw - draw function which must be called on update
48  */
49  "fnInit": function (oSettings, nPaging, fnCallbackDraw) {
50  var nInput = document.createElement('select');
51  var nPage = document.createElement('span');
52  var nOf = document.createElement('span');
53  nOf.className = "paginate_of";
54  nPage.className = "paginate_page";
55  if (oSettings.sTableId !== '') {
56  nPaging.setAttribute('id', oSettings.sTableId + '_paginate');
57  }
58  nInput.style.display = "inline";
59  nPage.innerHTML = "Page ";
60  nPaging.appendChild(nPage);
61  nPaging.appendChild(nInput);
62  nPaging.appendChild(nOf);
63  $(nInput).change(function (e) { // Set DataTables page property and redraw the grid on listbox change event.
64  window.scroll(0,0); //scroll to top of page
65  if (this.value === "" || this.value.match(/[^0-9]/)) { /* Nothing entered or non-numeric character */
66  return;
67  }
68  var iNewStart = oSettings._iDisplayLength * (this.value - 1);
69  if (iNewStart > oSettings.fnRecordsDisplay()) { /* Display overrun */
70  oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
71  fnCallbackDraw(oSettings);
72  return;
73  }
74  oSettings._iDisplayStart = iNewStart;
75  fnCallbackDraw(oSettings);
76  }); /* Take the brutal approach to cancelling text selection */
77  $('span', nPaging).bind('mousedown', function () {
78  return false;
79  });
80  $('span', nPaging).bind('selectstart', function () {
81  return false;
82  });
83  },
84 
85  /*
86  * Function: oPagination.listbox.fnUpdate
87  * Purpose: Update the listbox element
88  * Returns: -
89  * Inputs: object:oSettings - dataTables settings object
90  * function:fnCallbackDraw - draw function which must be called on update
91  */
92  "fnUpdate": function (oSettings, fnCallbackDraw) {
93  if (!oSettings.aanFeatures.p) {
94  return;
95  }
96  var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
97  var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; /* Loop over each instance of the pager */
98  var an = oSettings.aanFeatures.p;
99  for (var i = 0, iLen = an.length; i < iLen; i++) {
100  var spans = an[i].getElementsByTagName('span');
101  var inputs = an[i].getElementsByTagName('select');
102  var elSel = inputs[0];
103  if(elSel.options.length != iPages) {
104  elSel.options.length = 0; //clear the listbox contents
105  for (var j = 0; j < iPages; j++) { //add the pages
106  var oOption = document.createElement('option');
107  oOption.text = j + 1;
108  oOption.value = j + 1;
109  try {
110  elSel.add(oOption, null); // standards compliant; doesn't work in IE
111  } catch (ex) {
112  elSel.add(oOption); // IE only
113  }
114  }
115  spans[1].innerHTML = "&nbsp;of&nbsp;" + iPages;
116  }
117  elSel.value = iCurrentPage;
118  }
119  }
120 };