filter : exact match

filter : exact match

affablelochanaffablelochan Posts: 9Questions: 0Answers: 0
edited October 2011 in General
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

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    yes. use reg expression filtering. there is a param in fnFilter to trigger regexp

    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
  • affablelochanaffablelochan Posts: 9Questions: 0Answers: 0
    Hi fbas,

    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
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I don't see where you have defined the variable i.
  • affablelochanaffablelochan Posts: 9Questions: 0Answers: 0
    Hi fbas,

    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
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    yes, i can be whatever integer you need to indicate a column number (0-indexed, including hidden cols, I think. "0" will be the 1st column, "1" will be the 2nd column)

    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);
This discussion has been closed.