Search array of numbers for exact match

Search array of numbers for exact match

XanderJPNXanderJPN Posts: 2Questions: 1Answers: 0

I am trying to setup the search function on a table I am using. It is working great, except one of the columns (which is hidden) is an array of ids. I then have an "advance" search function where I allow the user to select a list of items, and then I want to use the selected items (array of int) to search through the hidden column. For example, if the column has [2, 3, 4, 11, 12] and the advance search returns [1] The search right now will return the row because it matches on [11, 12]. If I use regex for the exact match, it tries to match on the whole array, instead of just searching the ints in the array. Can someone please help me figure out how I can search an array of ints for exact matches?!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,281Questions: 26Answers: 4,940
    Answer ✓

    Not sure I fully understand what you are doing. Maybe you can post a test case showing your code and you you are attempting to do this.

    Does the advanced search return an array with one or multiple elements?

    I may be incorrect but the column would be a string with [2, 3, 4, 11, 12] or whatever. A simple regex search ('\\D' + val+ '\\D') could filter based on the match you want. Assuming val is an integer not an array.

    Kevin

  • XanderJPNXanderJPN Posts: 2Questions: 1Answers: 0
    edited July 2017

    That was close, but it lead me to the right answer. Thank you! This is what did it for me...

    var qualSearch = [];
    for (var i = 0; i < quals.length; i++)
    {
        qualSearch.push("\\b" + parseInt(quals[i]) + "\\b");
    }
    
    var search = qualSearch.join("|");
    _DTOWLInfoGrid.columns(7).search(qualSearch.join("|"), true, false, true);
    
    _DTOWLInfoGrid.draw();
    
This discussion has been closed.