How shall search be setup to find an exact number?

How shall search be setup to find an exact number?

mhjamhja Posts: 12Questions: 5Answers: 0

I get the search function to work, but when searching for a e.g. 0 all numbers having a 0 is shown, i.e. 0, 10, 20, etc.
How shall the search be set up to find exactly as input is given, i.e. 0 shows only 0 not 10, 20 or 30?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 18,571Questions: 26Answers: 4,406
    Answer ✓

    You will want to use a regex search, for example ^0$. Make sure to run off smart searching. Read more about the search modes in the search() docs. Looks like you are doing something similar as this example.

    Kevin

  • mhjamhja Posts: 12Questions: 5Answers: 0

    Thanks, yes it is similar to the mentioned example although for ease of use I will try to add the ^ and $ automatically.

  • kthorngrenkthorngren Posts: 18,571Questions: 26Answers: 4,406
    Answer ✓

    add the ^ and $ automatically.

    Look at line 13 of this example:
    https://datatables.net/examples/api/multi_filter_select.html

    Kevin

  • mhjamhja Posts: 12Questions: 5Answers: 0
    edited March 6

    Got it to function by using this

    function filterColumn(i) {
    if (i == '8') { 
        $a = $('#col' + i + '_filter').val();
        if ($a == "") {
            $a = $a;
        }else{
            $a = '^' + $a +'$';
        }
    } else {
        $a = $('#col' + i + '_filter').val();
    }
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Sign In or Register to comment.