Skip to content

Commit 230d02a

Browse files
committed
added clear ting
1 parent 6bf57b6 commit 230d02a

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
table.dataTable thead input, table.dataTable thead select {
22
width: 100%;
3-
}
3+
}
4+
5+
6+
7+
8+
9+
table.dataTable thead input[type=text]
10+
{
11+
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAABNSURBVHjaXI7BDcAwCAMvyQjMyQ6dAbZiKfqoUK34g2zJh1dENIC7M8pMAPYdzAVY3d0ajNz9aypS/b5R6o+ZPdqoKgCq6h80KH3xDgBqNR97p8oAGQAAAABJRU5ErkJggg==) no-repeat right -18px center;
12+
border: 1px solid #999;
13+
padding: 3px 18px 3px 4px; /* USE the same right padding in jQ! */
14+
border-radius: 3px;
15+
}
16+
table.dataTable thead input[type=text].x{
17+
background-position: right 5px center;
18+
}
19+
table.dataTable thead input[type=text].onX{
20+
cursor: pointer;
21+
}

media/js/jquery.dataTables.columnFilter.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
*/
2121
(function($) {
2222

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+
2333
var Delayer = (function () {
2434
var timer = 0;
2535
return function (callback, ms) {
@@ -111,7 +121,7 @@
111121
label = label.replace(/(^\s*)|(\s*$)/g, "");
112122
var currentFilter = oTable.fnSettings().aoPreSearchCols[i].sSearch;
113123
var search_init = 'search_init ';
114-
var inputvalue = label;
124+
var inputvalue = "";
115125
if (currentFilter != '' && currentFilter != '^') {
116126
if (bIsNumber && currentFilter.charAt(0) == '^')
117127
inputvalue = currentFilter.substr(1); //ignore trailing ^
@@ -120,7 +130,9 @@
120130
search_init = '';
121131
}
122132

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);
124136
if (iMaxLenght != undefined && iMaxLenght != -1) {
125137
input.attr('maxlength', iMaxLenght);
126138
}
@@ -135,7 +147,7 @@
135147

136148
if (bIsNumber && !oTable.fnSettings().oFeatures.bServerSide) {
137149
var delayer = new Delayer();
138-
input.keyup(function() {
150+
input.on("input", function() {
139151
var that = this;
140152
delayer.delay(function() {
141153
/* Filter on the column all numbers that starts with the entered value */
@@ -145,7 +157,7 @@
145157
});
146158
} else {
147159
var delayer = new Delayer();
148-
input.keyup(function() {
160+
input.on("input", function() {
149161
var that = this;
150162
delayer(function() {
151163
if (oTable.fnSettings().oFeatures.bServerSide && iFilterLength != 0) {
@@ -246,7 +258,7 @@
246258
//------------end range filtering function
247259

248260
var delay = new Delayer();
249-
$('#' + sFromId + ',#' + sToId, th).keyup(function() {
261+
$('#' + sFromId + ',#' + sToId, th).on("input", function() {
250262
delay(function() {
251263
var iMin = document.getElementById(sFromId).value * 1;
252264
var iMax = document.getElementById(sToId).value * 1;
@@ -850,7 +862,7 @@
850862
};
851863
}
852864

853-
865+
$('table.dataTable thead input[type=text]').trigger("input")
854866
});
855867

856868

0 commit comments

Comments
 (0)