Skip to content

Commit 002f3e8

Browse files
committed
v 1.5.3. Added support for {value, label} for the checkboxes.
1 parent 591cb63 commit 002f3e8

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

checkbox.html

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,28 @@
3636

3737
<script type="text/javascript" charset="utf-8">
3838
$(document).ready( function () {
39-
$('#example').dataTable().columnFilter({ /*sPlaceHolder: "head:after",*/ aoColumns: [
40-
{ type: "checkbox", values: null /*[ 'Gecko', 'Trident', 'KHTML', 'Misc', 'Presto', 'Tasman', 'Webkit']*/ },{},{},{},{ type: "checkbox", values: [ 'A', 'B', 'C', 'U', 'X'] } ]});
39+
$('#example')
40+
.dataTable()
41+
.columnFilter(
42+
{ /*sPlaceHolder: "head:after",*/
43+
aoColumns:
44+
[ { type: "checkbox", values: null /*[ 'Gecko', 'Trident', 'KHTML', 'Misc', 'Presto', 'Tasman', 'Webkit']*/ },
45+
{},
46+
{},
47+
{},
48+
{
49+
type: "checkbox",
50+
values:
51+
[
52+
{value: 'A', label: 'Grade A' },
53+
{value: 'B', label: 'Grade B' },
54+
{value: 'C', label: 'Grade C' },
55+
'U',
56+
'X'
57+
]
58+
}
59+
]
60+
});
4161
} );
4262
</script>
4363
<script type="text/javascript">

media/js/jquery.dataTables.columnFilter.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* File: jquery.dataTables.columnFilter.js
3-
* Version: 1.5.2.
3+
* Version: 1.5.3.
44
* Author: Jovan Popovic
55
*
66
* Copyright 2011-2014 Jovan Popovic, all rights reserved.
@@ -479,8 +479,16 @@
479479
r += divClose + divRowDef;
480480
}
481481

482+
var sLabel = aData[j];
483+
var sValue = aData[j];
484+
485+
if (typeof (aData[j]) == 'object') {
486+
sLabel = aData[j].label;
487+
sValue = aData[j].value;
488+
}
489+
482490
//check button
483-
r += '<input class="search_init checkbox_filter" type="checkbox" id= "' + aData[j] + '" name= "' + localLabel + '" value="' + aData[j] + '" >' + aData[j] + '<br/>';
491+
r += '<input class="search_init checkbox_filter" type="checkbox" id= "' + uniqueId + '_cb_' + sValue + '" name= "' + localLabel + '" value="' + sValue + '" >' + sLabel + '<br/>';
484492

485493
var checkbox = $(r);
486494
th.html(checkbox);
@@ -506,13 +514,21 @@
506514

507515
});
508516

517+
518+
if (search != "") {
519+
$('input:checkbox[name="' + localLabel + '"]').removeClass("search_init");
520+
} else {
521+
$('input:checkbox[name="' + localLabel + '"]').addClass("search_init");
522+
}
523+
/* Old code for setting search_init CSS class on checkboxes if any of them is checked
509524
for (var jj = 0; jj < iLen; jj++) {
510525
if (search != "") {
511526
$('#' + aData[jj]).removeClass("search_init");
512527
} else {
513528
$('#' + aData[jj]).addClass("search_init");
514529
}
515530
}
531+
*/
516532

517533
//execute search
518534
oTable.fnFilter(search, index, true, false);

serverSideInitFilter.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,35 @@
4141
var oSettings = $dt.fnSettings();
4242
oSettings.aoPreSearchCols[ 0 ].sSearch = "Trident";
4343
oSettings.aoPreSearchCols[ 1 ].sSearch = "5";
44+
oSettings.aoPreSearchCols[ 4 ].sSearch = "C";
4445
//$dt.fnDraw();
4546

4647
$dt.columnFilter({
4748
aoColumns: [
4849
{ type: "select", values: [ 'Gecko', 'Trident "New"', 'Trident', 'KHTML', 'Misc', 'Presto', 'Webkit', 'Tasman'] },
4950
{ type: "text" },
5051
{ type: "text" },
51-
{ type: "text" }
52+
{ type: "text" },
53+
{
54+
type: "checkbox",
55+
values:
56+
[
57+
{ value: 'A', label: 'Grade A' },
58+
{ value: 'B', label: 'Grade B' },
59+
{ value: 'C', label: 'Grade C' },
60+
'U',
61+
'X'
62+
]
63+
}
5264
]
5365
});
5466

5567
$("[rel=0]", $dt).val("Trident");
5668
$("[rel=1]", $dt).val("5");
57-
69+
$("div[rel=4] input[type=checkbox][value=C]")
70+
.each(function() {
71+
this.checked = true;
72+
});
5873
} );
5974
</script>
6075
<script type="text/javascript">

0 commit comments

Comments
 (0)