DT column.search() multiple values -- and condition

DT column.search() multiple values -- and condition

dmeisterdmeister Posts: 10Questions: 2Answers: 0

Hi,
I have the function below which is supposed perform an "and" filter on a DT column that has multiple values. I add the values to an array based on the values checked and then perform a join. The commented out reg-ex function below worked beautifully when I performed the join with a "|" but it is an "or" condition. I'd like to be able to determine whether the value "Mental health" and "Physical health" exist in the column. The data in the column is "|" delimited but I can change that if necessary. The function below returns no items when the checkboxes with the sample values I listed are used even though they both exist in the column. Any advice will be appreciated.

        function chkBoxfilterTopics(chkBox) {
            //alert("value: " + chkBox.value + " checked:" + chkBox.checked)
                                                            if (chkBox.checked) {
                                                                            topicsMPGFilters.push(chkBox.value);
                                                            }
                                                            else {
                                                                            const index = topicsMPGFilters.indexOf(chkBox.value);
                                                                            if (index > -1) {
                                                                                            topicsMPGFilters.splice(index, 1);
                                                                            }
                                                            }
                                                            var srchVal = topicsMPGFilters.join(" ");
            var colnum = 16; // column number holding topicsMPG (0 based)
            //tblPrograms.columns(colnum).search(srchVal,true,false,false).draw(); // reg-ex
            tblPrograms.columns(colnum).search(srchVal,false,true,false).draw();                                                  
        }

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • dmeisterdmeister Posts: 10Questions: 2Answers: 0

    Thanks Colin. It appears the code I provided above was working. Thanks for responding.

This discussion has been closed.