Regex with 'OR' condition doens't work in fnFilter

Regex with 'OR' condition doens't work in fnFilter

vaasugivvaasugiv Posts: 5Questions: 0Answers: 0
edited February 2014 in DataTables 1.9
Hi Alan,

I used the DataTables Debug BookMarklet to upload my datatables and the debug code is 'olohos'.

My issue is, the OR operator '|' or even '||' with string values to filter a column doesn't work in my web application.

For example, if I have the code below

$('.search_init').keyup(function()
{
var asEscapedFilters = [];
asEscapedFilters[0] = $(this).val();
asEscapedFilters[1] = 'Y';
oTable.fnFilter(asEscapedFilters[0] | asEscapedFilters[1], $('#example tr.inputs input').index(this), true, false);
});

And input the string 'I' in the search area for the 'Order Active' column, it is supposed to return all the rows which contains either 'I' or 'Y' for the 'Order Active' column. Instead it returns zero rows.

If I use '||' instead of '|' like the below,

$('.search_init').keyup(function()
{
var asEscapedFilters = [];
asEscapedFilters[0] = $(this).val();
asEscapedFilters[1] = 'Y';
oTable.fnFilter(asEscapedFilters[0] || asEscapedFilters[1], $('#example tr.inputs input').index(this), true, false);
});

It returns the rows which have 'Y' for the 'Order Active' column, but not the rows with 'I'.

I have already spent a lot of time, looking at this issue, any useful suggestions to get this work is very much appreciated.

The processing is server side, does it requires it to take care of any additional syntax or settings for this?

Many thanks in advance,
Vaasugi.

Replies

  • vaasugivvaasugiv Posts: 5Questions: 0Answers: 0
    When using the second example,

    $('.search_init').keyup(function()
    {
    var asEscapedFilters = [];
    asEscapedFilters[0] = $(this).val();
    asEscapedFilters[1] = 'Y';
    oTable.fnFilter(asEscapedFilters[0] || asEscapedFilters[1], $('#example tr.inputs input').index(this), true, false);
    });

    If I input a string/character, say 'I' in the search area of the 'Order Active' column,

    asEscapedFilters[0] || asEscapedFilters[1] returns 'I' and the filtering is done for 'I'

    If I backspace and enter, (input blank), in the search area of the 'Order Active' column,

    asEscapedFilters[0] || asEscapedFilters[1] returns 'Y' and the filtering is done for 'Y'

    It is so weird and Im unable to get the filtering done for 'I | Y' at any time.
  • vaasugivvaasugiv Posts: 5Questions: 0Answers: 0
    edited March 2014
    Hi Allan, any help on this?
    I tried the below as well, with no luck so far.

    $('.search_init').keyup(function()
    {
    var string1 = $(this).val();
    var string2 = 'Y';
    var filterRegEx1 = '(' + string1 + '|' + string2 + ')';
    //var filterRegEx2 = new RegExp(string1 + '|' + string2);
    oTable.fnFilter(filterRegEx1, $('#example tr.inputs input').index(this), true, false);
    });

    Neither the regular expression literal (filterRegEx1) no the regular expression object (filterRegEx2) works in my fnFilter. I have made the third argument true and the fourth argument false, as suggested by you in the the answers for others' questions.

    I also tried with the earlier versions of DataTables, still nothing worked in my favour.
This discussion has been closed.