Search in two columns with multiple values separated by a pipe
Search in two columns with multiple values separated by a pipe
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
Here i sone option:
http://live.datatables.net/wenaxuti/226/edit
It uses an OR search between the Position and Office columns. You cna change it to AND if that is a requirement.
Kevin
I try like this, but i've no solution
http://live.datatables.net/buculiqa/1/edit
You are getting this console error:
You changed the second parameter in the search plugin from
searchData
toa
. I changed it back.You are pointing to the wrong column. I changed
filters.includes(searchData[3])
tofilters.includes(searchData[4])
.Now this search works:
http://live.datatables.net/wejacuqe/1/edit
Kevin
Thank you Kevin, yes, you are right, it's my mistake. Is it possible to filter with a part of the text, like col|nna. but not the complete value
In the search plugin you can use any supported Javascript method like regex search().
Kevin
Thanks Kevin, all is correct.