Search in two columns with multiple values separated by a pipe

Search in two columns with multiple values separated by a pipe

adf_espoiradf_espoir Posts: 4Questions: 1Answers: 0

I'd like to filter my table with a multiple values "condition1|condition2|..." and on two columns 0 and 4.
` $.fn.dataTable.ext.search.push(function (settings, data, dataIndex) {
var comp = $('#search-me').val();
let vName = "";
let vFatherName = "";
if (data[0]) {
vName = data[0].toLowerCase();
}
if (data[4]) {
vFatherName = data[4].toLowerCase();
}

        if (comp !== "") {
           let arrComp = comp.split('|');
           if (arrComp.length > 1) {
                arrComp.forEach((item) => {
                    if (vName.indexOf(item.toLowerCase()) > 0 || vFatherName.indexOf(item.toLowerCase()) > 0) {
                        console.log(item);
                        return true;
                    } else {
                        item == "";
                    }
                });
           } else {
               return vName.indexOf(comp.toLowerCase()) > 0 || vFatherName.indexOf(comp.toLowerCase()) > 0;
           }
        } else  {
            return comp == ""; 
        }
    });`

Please help me.

This question has accepted answers - jump to:

Answers

Sign In or Register to comment.