I'm trying to build up custom search function that implements inclusive or logic across multiple columns using multiple criteria, but I can't seem to get it work properly - search returns empty result set.
My HTML:
<!doctype html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="test2.js"></script>
<script src="mFilter.js"></script>
<link rel="stylesheet" type="text/css" href="test.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
</head>
<body>
<table id="mytable"></table>
<button id="mybutton">Search for apple and vegies</button>
</body>
</html>
My jQuery:
var srcData = [
{name:"apple", category:"fruit"},
{name:"banana", category:"fruit"},
{name:"cabage", category:"vegie"},
{name:"carrot", category:"vegie"},
];
var dataTable = $('#mytable').DataTable({
sDom: 't',
data: srcData,
columns: [
{data: 'name', title: 'Name'},
{data: 'category', title: 'Category'}
]
});
$.fn.DataTable.ext.search.push(function(settings, searchData, index, rowData){
if(rowData.name == searchData[0] || rowData.category == searchData[1]) return true;
else return false;
});
$('#mybutton').on('click', function(){
dataTable.search(['apple','vegie']).draw();
});
and jsfiddle, just in case. Any help is greatly appreciated.