filter not working if text contains space

filter not working if text contains space

SriRishithaSriRishitha Posts: 42Questions: 4Answers: 0

filter not working if text contains space like this (user name)

Replies

  • SriRishithaSriRishitha Posts: 42Questions: 4Answers: 0

    hello any one give me reply
    for example when i type user n the filter is not working, when i type user na it is working properly.

  • SriRishithaSriRishitha Posts: 42Questions: 4Answers: 0

    http://jsfiddle.net/Lnvbnp6c/
    i tries this sample also
    when i type "system" the result is 3 rows,
    when i type "system a" the result also 3 rows,
    when i type "system ar" the result is 1 rows,
    can any one tell me the solution

  • kthorngrenkthorngren Posts: 21,364Questions: 26Answers: 4,956

    There are a couple of problems. Your custom search box isn't working at all. You have a couple errors to fix first:

    $('#search-inp').keyup(function(){
        var term = $(this).val(),    <<<the comma should be a semi-colon
            regex = '\\b' + term + '\\b';
    
        removeHighlight();
        table.columns(1).search(regex, true, false);  <<< this should be column 2, also need to add .draw() at the end
        highlight(term);
    })
    

    In order to help with the regex search term please describe specifically what you want it to do.

    Kevin

  • SriRishithaSriRishitha Posts: 42Questions: 4Answers: 0

    its sample i taken from net to show the problem in search.
    **https://datatables.net/examples/api/regex.html ** in this also searching like that format only.
    i am not using any custom search. i am using default filtering :true option

  • kthorngrenkthorngren Posts: 21,364Questions: 26Answers: 4,956

    i am not using any custom search.

    Your test case creates an additional input box with the ID of search-inp. This is the custom search box I'm referring to. This is the input your keyup event is attaching to.

    In the regex example when you search the Position column using Smart Search then you see the behavior you describe above. The search() docs describe Smart Searching and I think you are seeing the results of "Partial word matching". However if you turn of Smart Search and enable Regex then "system " will result in one row not three.

    If I understand your question correctly you need to change this line in your code:
    table.columns(1).search(regex, true, false);

    To this:
    table.columns(2).search(term, true, false);

    Your position column is in column 2 not 1. You can just search the term variable. Your regex value won't work unless you fully type system and architect.

    Kevin

  • SriRishithaSriRishitha Posts: 42Questions: 4Answers: 0

    i am not using the custom search.

This discussion has been closed.