|
20 | 20 | */ |
21 | 21 | (function($) { |
22 | 22 |
|
| 23 | + var Delayer = (function () { |
| 24 | + var timer = 0; |
| 25 | + return function (callback, ms) { |
| 26 | + clearTimeout(timer); |
| 27 | + timer = setTimeout(callback, ms); |
| 28 | + }; |
| 29 | + }); |
| 30 | + |
23 | 31 |
|
24 | 32 | $.fn.columnFilter = function(options) { |
25 | 33 | var columnBuilders = $.merge({}, options.columnBuilders || {}); |
|
126 | 134 | var index = i; |
127 | 135 |
|
128 | 136 | if (bIsNumber && !oTable.fnSettings().oFeatures.bServerSide) { |
| 137 | + var delayer = new Delayer(); |
129 | 138 | input.keyup(function() { |
130 | | - /* Filter on the column all numbers that starts with the entered value */ |
131 | | - oTable.fnFilter('^' + this.value, _fnColumnIndex(index), true, false); //Issue 37 |
132 | | - fnOnFiltered(); |
| 139 | + var that = this; |
| 140 | + delayer.delay(function() { |
| 141 | + /* Filter on the column all numbers that starts with the entered value */ |
| 142 | + oTable.fnFilter('^' + that.value, _fnColumnIndex(index), true, false); //Issue 37 |
| 143 | + fnOnFiltered(); |
| 144 | + }, properties.iFilteringDelay); |
133 | 145 | }); |
134 | 146 | } else { |
| 147 | + var delayer = new Delayer(); |
135 | 148 | input.keyup(function() { |
136 | | - if (oTable.fnSettings().oFeatures.bServerSide && iFilterLength != 0) { |
137 | | - //If filter length is set in the server-side processing mode |
138 | | - //Check has the user entered at least iFilterLength new characters |
139 | | - |
140 | | - var currentFilter = oTable.fnSettings().aoPreSearchCols[index].sSearch; |
141 | | - var iLastFilterLength = $(this).data("dt-iLastFilterLength"); |
142 | | - if (typeof iLastFilterLength == "undefined") |
143 | | - iLastFilterLength = 0; |
144 | | - var iCurrentFilterLength = this.value.length; |
145 | | - if (Math.abs(iCurrentFilterLength - iLastFilterLength) < iFilterLength |
146 | | - //&& currentFilter.length == 0 //Why this? |
147 | | - ) { |
148 | | - //Cancel the filtering |
149 | | - return; |
150 | | - } else { |
151 | | - //Remember the current filter length |
152 | | - $(this).data("dt-iLastFilterLength", iCurrentFilterLength); |
| 149 | + var that = this; |
| 150 | + delayer(function() { |
| 151 | + if (oTable.fnSettings().oFeatures.bServerSide && iFilterLength != 0) { |
| 152 | + //If filter length is set in the server-side processing mode |
| 153 | + //Check has the user entered at least iFilterLength new characters |
| 154 | + |
| 155 | + var currentFilter = oTable.fnSettings().aoPreSearchCols[index].sSearch; |
| 156 | + var iLastFilterLength = $(that).data("dt-iLastFilterLength"); |
| 157 | + if (typeof iLastFilterLength == "undefined") |
| 158 | + iLastFilterLength = 0; |
| 159 | + var iCurrentFilterLength = that.value.length; |
| 160 | + if (Math.abs(iCurrentFilterLength - iLastFilterLength) < iFilterLength |
| 161 | + //&& currentFilter.length == 0 //Why this? |
| 162 | + ) { |
| 163 | + //Cancel the filtering |
| 164 | + return; |
| 165 | + } else { |
| 166 | + //Remember the current filter length |
| 167 | + $(that).data("dt-iLastFilterLength", iCurrentFilterLength); |
| 168 | + } |
153 | 169 | } |
154 | | - } |
155 | | - /* Filter on the column (the index) of this element */ |
156 | | - oTable.fnFilter(this.value, _fnColumnIndex(index), regex, smart); //Issue 37 |
157 | | - fnOnFiltered(); |
| 170 | + /* Filter on the column (the index) of this element */ |
| 171 | + oTable.fnFilter(that.value, _fnColumnIndex(index), regex, smart); //Issue 37 |
| 172 | + fnOnFiltered(); |
| 173 | + }, properties.iFilteringDelay); |
158 | 174 | }); |
159 | 175 | } |
160 | 176 |
|
|
229 | 245 | ); |
230 | 246 | //------------end range filtering function |
231 | 247 |
|
232 | | - |
| 248 | + var delay = new Delayer(); |
233 | 249 | $('#' + sFromId + ',#' + sToId, th).keyup(function() { |
| 250 | + delay(function() { |
| 251 | + var iMin = document.getElementById(sFromId).value * 1; |
| 252 | + var iMax = document.getElementById(sToId).value * 1; |
| 253 | + if (iMin != 0 && iMax != 0 && iMin > iMax) |
| 254 | + return; |
234 | 255 |
|
235 | | - var iMin = document.getElementById(sFromId).value * 1; |
236 | | - var iMax = document.getElementById(sToId).value * 1; |
237 | | - if (iMin != 0 && iMax != 0 && iMin > iMax) |
238 | | - return; |
239 | | - |
240 | | - oTable.fnDraw(); |
241 | | - fnOnFiltered(); |
| 256 | + oTable.fnDraw(); |
| 257 | + fnOnFiltered(); |
| 258 | + }, properties.iFilteringDelay); |
242 | 259 | }); |
243 | | - |
244 | | - |
245 | 260 | } |
246 | 261 |
|
247 | 262 |
|
|
332 | 347 | } |
333 | 348 | ); |
334 | 349 | //------------end date range filtering function |
335 | | - |
| 350 | + var delayer = new Delayer() |
336 | 351 | $('#' + sFromId + ',#' + sToId, th).change(function() { |
337 | | - oTable.fnDraw(); |
338 | | - fnOnFiltered(); |
| 352 | + delayer(function() { |
| 353 | + oTable.fnDraw(); |
| 354 | + fnOnFiltered(); |
| 355 | + }, properties.iFilteringDelay); |
339 | 356 | }); |
340 | 357 |
|
341 | 358 |
|
|
0 commit comments