Searching multiple values using checkbox filters

Searching multiple values using checkbox filters

neelam_citeneelam_cite Posts: 6Questions: 2Answers: 0

How do I search multiple values using checkbox filters?

I have some hidden columns with data and I need to assign multiple values to some of them that would then come if the search was filtered.

For example:

Region is a search filter and I have some checkboxes that the user can filter by, I want to assign more than one value per column or <td> that can then be searched.

Here is a fiddle with what I am trying to achieve

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @neelam_cite ,

    It looks close. You need to change this section of the code here:

          if (region.indexOf(searchData[5]) !== -1) {
            return true;
          }
    

    If you use split() to breakdown searchData[5] on a comma, and just iterate through them to see if any are in your region array.

    Hope that helps,

    Colin

  • neelam_citeneelam_cite Posts: 6Questions: 2Answers: 0

    Hi @colin

    I'm not sure I understand how to do that?

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @neelam_cite ,

    See here. You just need to split() the regions:

          var regs = searchData[5].split(',');
          for (var i = 0; i < regs.length; i++) {
            if (region.indexOf(regs[i].replace(/^\s+|\s+$/g, '')) !== -1) {
                return true;
            }
          }
    

    Cheers,

    Colin

    p.s. I'm old school, I like for() loops, you might want to change that to be every()

  • neelam_citeneelam_cite Posts: 6Questions: 2Answers: 0
    edited July 2019

    Thanks @colin that really helped, I have some values like: Yorkshire and Humber but they don't seem to be picked up when the checkbox is clicked, does the regex need to be updated?

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @neelam_cite ,

    In that example I posed last, "Sarah Smith" from "Yorkshire and Humber" is being picked out - she's the only one from there in that dataset. Could you give instructions, please, with that example on how to reproduce the problem you're seeing.

    Cheers,

    Colin

  • neelam_citeneelam_cite Posts: 6Questions: 2Answers: 0

    Hi @colin ,

    Please ignore me, you are correct it does work. I have accepted your answer as the correct one.

    Thank you for all your help!

This discussion has been closed.