Closed GoogleCodeExporter closed 8 years ago
I had the same issue, if you add "bRegex": true to the options statement e.g.
{type: "select", "values": [ 'Active', 'Dead', 'Inactive'], "bRegex": true },
Then change the function fnCreateSelect to the following (very slight set of
changes) and your drop-downs/select will do exact matching
function fnCreateSelect(oTable, aData) {
var index = i;
var r = '<select class="search_init select_filter"><option value="" class="search_init">' + label + '</option>', j, iLen = aData.length;
for (j = 0; j < iLen; j++) {
r += '<option value="' + aData[j] + '">' + aData[j] + '</option>';
}
var select = $(r + '</select>');
// modification added regex variable, added val variable and added if clause to
// prepend "^" and append "$" for regex filtering of the column to only return exact matches to drop-down lists
var regex = false;
th.html(select);
th.wrapInner('<span class="filterColumn filter_select" />');
select.change(function () {
var val = $(this).val();
if (val != "") {
regex = true;
$(this).removeClass("search_init");
} else {
regex = false;
$(this).addClass("search_init");
}
if (regex) {
val = '^'+val+'$';
}
oTable.fnFilter(val, index, regex);
});
}
Original comment by scott.zi...@gmail.com
on 12 Jul 2011 at 10:24
Scott, thanks for the tip.
Original comment by yfn...@gmail.com
on 13 Jul 2011 at 3:41
Thanks for this comment.
I'm closing this issue.
Thanks,
Jovan
Original comment by joc...@gmail.com
on 25 Sep 2011 at 1:36
Am using datatable filter, I have fromdate column with the following values
Jul 15,2012 and Jul 5,2012. If am select Jul 5,2012 values, it's return both
values.
As per above code changed, but it's not working
Code
$("#fromDate",this).change( function () {
var regex = false;
var val = this.value;
if (val != "") {
regex = true;
} else {
regex = false;
}
if (regex) {
val = '^'+val+'$';
}
oTable.fnFilter( val, $(".filters th input").index(this),regex);
} );
Above code no result.
If i change
val = '^'+val+'$'; => val = val; means, return 2 values.
Please help me to fix this issue
Original comment by raj.ama...@gmail.com
on 15 Jun 2012 at 1:48
JQuery DataTables - Filter column by exact match
oTable.fnFilter( "^"+TERM+"$", COLUMN , true); //Term, Column #, RegExp Filter
$(document).ready(function() {
tbl = $('#example').dataTable();
tbl.fnFilter("^" + filter_value + "$");
});
$(document).ready( function() {
$('#example').dataTable( {
"oSearch": {"bSmart": false}
} );
} )
Original comment by mrkraju1...@gmail.com
on 13 Feb 2014 at 10:03
Original issue reported on code.google.com by
yfn...@gmail.com
on 29 Jun 2011 at 6:48