Global Search with RegEx only checking column 0?

Global Search with RegEx only checking column 0?

friarpatfriarpat Posts: 2Questions: 1Answers: 0

Should a global search with RegEx check all columns (not just column 0)?

Using the interface at

https://datatables.net/examples/api/regex.html

In the Global Search:
If I enter 'Ash', leave the SmartSearch checked - I get 2 results. Good.

If I enter 'Ash', check RegEx, uncheck Smart Search - I get 2 results. Good.

If I enter '^Ash', check RegEx, uncheck Smart Search - I get 1 result, beginning with 'Ash'. Good - we know the regex functionality is working.

If I enter 'Acc', check RegEx, uncheck Smart Search - I get 2 results, with Accountant from the 2nd column. Good.

If I enter '^Acc', check RegEx, uncheck Smart Search - I get no results....

Shouldn't I get the same two results even though the results would come from the second column?

Thanks!

Answers

  • friarpatfriarpat Posts: 2Questions: 1Answers: 0

    FWIW...and just to hear the shriek/gasp for this solution - I changed the _fnFilter from:

                for ( i=display.length-1 ; i>=0 ; i-- ) {
                    if ( ! rpSearch.test( settings.aoData[ display[i] ]._sFilterRow ) ) {
                        display.splice( i, 1 );
                    }
                }
    

    to ....

    for ( i=display.length-1 ; i>=0 ; i-- ) {
        if(smart)
        {
            if ( ! rpSearch.test( settings.aoData[ display[i] ]._sFilterRow ) ) {
                display.splice( i, 1 );
            }
        }
        else
        {
            // The _sFilterRow appears to be white space separated.  If a regex is applied
            // for the global search it applies the regex against the entire string.  It should
            // be looking at each individual column instead.
            // _sFilterRow is put together using a join with 2 spaces between each 
                    // column.
            // The following will blow up in the case that a column has text that has at least 
            // 2 sequential spaces in it - but it works for this situation.
            var columnValues = settings.aoData[ display[i] ]._sFilterRow.split(/\s{2,}/);
            var matchFound = false;
            for(var x = 0; x < columnValues.length; x++)
            {
                if(rpSearch.test(columnValues[x]))
                {
                    matchFound = true;
                    break;
                }
            }
            if(!matchFound)
            {
                display.splice(i,1);
            }
            
        }
    }
    
    

    I realize this relies on making sure the smartSearch flag is set to false when setting up the search. It certainly blows up should a column have 2+ sequential spaces in it...but it does give me the behavior I was expecting when doing a global search using a regular expression.

    If there is a better way around this - please let me know!

This discussion has been closed.