Update the searchData before search.
Update the searchData before search.
Leutecia
Posts: 3Questions: 1Answers: 0
table.columns(0).search($("#searchInput").val()).draw();
Using this code to search, but actually, I need to remove the numbers from that column. How can I achieve that?
I saw this code for extending the search:
$.fn.dataTable.ext.search.push(
function( settings, searchData, index, rowData, counter ) {
console.log('searchData', searchData[0])
searchData = searchData[0].replace(/[0-9]/g, '');
return true;
}
);
It doesn't work. I just need to update that searchData text.
This discussion has been closed.
Answers
You could use orthogonal data to remove the numbers for the
filter
operation. Then you wouldn't need to use a search plugin.The search plugin is meant to perform comparisons, which you don't have. See this example. It gets the input value then performs a comparison with the data. Just use
draw()
to have the plugin execute. If you want to use the search plugin do something like this:Use
table.draw()
to execute the search plugin.Kevin
Thanks for your answer.
Sadly, It's not working.
I don't understand your solution, myData will never be equal to val, so no search will be performed.
Could you please explain how I could solve this using the orthogonal data with an example?
Hey @kthorngren
The orthogonal way worked like a charm. Didn't know this even existed. Massive thanks to you.
Here's how I fixed it. In my columns array: