|
20 | 20 | */ |
21 | 21 | (function($) { |
22 | 22 |
|
| 23 | + function tog(v) { return v ? 'addClass' : 'removeClass'; } |
| 24 | + |
| 25 | + $(document).on('input change', 'table.dataTable thead input[type=text]', function () { |
| 26 | + $(this)[tog(this.value && !$(this).hasClass("search_init"))]('x'); |
| 27 | + }).on('mousemove', '.x', function (e) { |
| 28 | + $(this)[tog(this.offsetWidth - 18 < e.clientX - this.getBoundingClientRect().left)]('onX'); |
| 29 | + }).on('click', '.onX', function () { |
| 30 | + $(this).removeClass('x onX').val('').trigger("input").trigger("change"); |
| 31 | + }); |
| 32 | + |
23 | 33 | var Delayer = (function () { |
24 | 34 | var timer = 0; |
25 | 35 | return function (callback, ms) { |
|
111 | 121 | label = label.replace(/(^\s*)|(\s*$)/g, ""); |
112 | 122 | var currentFilter = oTable.fnSettings().aoPreSearchCols[i].sSearch; |
113 | 123 | var search_init = 'search_init '; |
114 | | - var inputvalue = label; |
| 124 | + var inputvalue = ""; |
115 | 125 | if (currentFilter != '' && currentFilter != '^') { |
116 | 126 | if (bIsNumber && currentFilter.charAt(0) == '^') |
117 | 127 | inputvalue = currentFilter.substr(1); //ignore trailing ^ |
|
120 | 130 | search_init = ''; |
121 | 131 | } |
122 | 132 |
|
123 | | - var input = $('<input type="text" class="' + search_init + sCSSClass + '" value="' + inputvalue + '" rel="' + i + '"/>'); |
| 133 | + var input = $('<input type="text" class="' + search_init + sCSSClass + '" rel="' + i + '"/>') |
| 134 | + .val(inputvalue) |
| 135 | + .attr("placeholder", label); |
124 | 136 | if (iMaxLenght != undefined && iMaxLenght != -1) { |
125 | 137 | input.attr('maxlength', iMaxLenght); |
126 | 138 | } |
|
135 | 147 |
|
136 | 148 | if (bIsNumber && !oTable.fnSettings().oFeatures.bServerSide) { |
137 | 149 | var delayer = new Delayer(); |
138 | | - input.keyup(function() { |
| 150 | + input.on("input", function() { |
139 | 151 | var that = this; |
140 | 152 | delayer.delay(function() { |
141 | 153 | /* Filter on the column all numbers that starts with the entered value */ |
|
145 | 157 | }); |
146 | 158 | } else { |
147 | 159 | var delayer = new Delayer(); |
148 | | - input.keyup(function() { |
| 160 | + input.on("input", function() { |
149 | 161 | var that = this; |
150 | 162 | delayer(function() { |
151 | 163 | if (oTable.fnSettings().oFeatures.bServerSide && iFilterLength != 0) { |
|
246 | 258 | //------------end range filtering function |
247 | 259 |
|
248 | 260 | var delay = new Delayer(); |
249 | | - $('#' + sFromId + ',#' + sToId, th).keyup(function() { |
| 261 | + $('#' + sFromId + ',#' + sToId, th).on("input", function() { |
250 | 262 | delay(function() { |
251 | 263 | var iMin = document.getElementById(sFromId).value * 1; |
252 | 264 | var iMax = document.getElementById(sToId).value * 1; |
|
850 | 862 | }; |
851 | 863 | } |
852 | 864 |
|
853 | | - |
| 865 | + $('table.dataTable thead input[type=text]').trigger("input") |
854 | 866 | }); |
855 | 867 |
|
856 | 868 |
|
|
0 commit comments