filter : exact match
filter : exact match
affablelochan
Posts: 9Questions: 0Answers: 0
Hi Everybody,
So this is my second post. I was asked if i can filter exactly same value that i enter in search box. I have searched similar posts but i am way inexperienced to understand those smart conversations.
I am using following script i found in one of the discussion to filter on hitting return key
[code]
// jquery plugin
$.fn.dataTableExt.oApi.fnFilterOnReturn = function (oSettings) {
var _that = this;
this.each(function (i) {
$.fn.dataTableExt.iApiIndex = i;
var $this = this;
var anControl = $('input', _that.fnSettings().aanFeatures.f);
anControl.unbind('keyup').bind('keypress', function (e) {
if (e.which == 13) {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter(anControl.val());
}
});
return this;
});
return this;
}
[/code]
Is there are way to add in this script "fnFilter" to make use of ^ and $ to filter exactly what i type? Kindly help me with this.
Regards
Rajiv
So this is my second post. I was asked if i can filter exactly same value that i enter in search box. I have searched similar posts but i am way inexperienced to understand those smart conversations.
I am using following script i found in one of the discussion to filter on hitting return key
[code]
// jquery plugin
$.fn.dataTableExt.oApi.fnFilterOnReturn = function (oSettings) {
var _that = this;
this.each(function (i) {
$.fn.dataTableExt.iApiIndex = i;
var $this = this;
var anControl = $('input', _that.fnSettings().aanFeatures.f);
anControl.unbind('keyup').bind('keypress', function (e) {
if (e.which == 13) {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter(anControl.val());
}
});
return this;
});
return this;
}
[/code]
Is there are way to add in this script "fnFilter" to make use of ^ and $ to filter exactly what i type? Kindly help me with this.
Regards
Rajiv
This discussion has been closed.
Replies
kindly read http://www.datatables.net/api#fnFilter
oTable.fnFilter(searchstr, null, true); // global search
oTable.fnFilter(searchstr, colnum, true); // search for just one column
I added the oTable sinppet as follows.
[code]
$(document).ready(function() {
$(".dataTable").dataTable( {
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "all"]]
} );
$('.dataTable').dataTable().sparsify();
$('.dataTable').dataTable().fnFilterOnReturn();
} );
var oTable;
$(document).ready(function() {
oTable = $('.dataTable').dataTable();
oTable.fnFilter( "^"+searchstr+"$", i , true);
} );
[/code]
This code is not working. Can you tell me what should i change in this so that it works? Thank you in advance.
Rajiv
I did not define variable i anywhere. From above code,
"oTable.fnFilter( "^"+searchstr+"$", i , true);"
How to replace the searchstr and column number in the above case.? Can i replace column number with just 1 as i need to filter based on first column?
Regards
Rajiv
as for the search string, you'd take the value from a textbox that you'll need to set up.
oTable.fnFilter( "^"+$('#mytextbox').val()+"$", 1 , true);