How do I create a search that looks for multiple things?
How do I create a search that looks for multiple things?
I have a map and when you click a state on it, my DataTable searches Column 7 for that state and displays all rows with it. So this works on click:
table.columns(7).search('"'+clickedState+'"', true, false).draw();
However, I now need it to also search in Column 8 for rows that match "Red" and I can't figure out how to modify that to include both. I've tried several different things and nothing is working. I'm sure it's something small i'm missing.
Psuedo code would be: if column 7 contains "clickedState" OR column 8 contains "Red", draw those rows.
Here is the demo I just set up: http://live.datatables.net/mejaxohi/1/edit
Answers
Okay I figured it out. On click, do this:
$.fn.dataTable.ext.search.push(function( settings, data, dataIndex ) {
if ( data[7] == clickedState || data[8] == "Red" ){
return true
}else{
return false;
}
});
table.draw();