FuzzySearch on selected columns
FuzzySearch on selected columns

I want to use FuzzySearch but only on selected columns
- I have a table with FuzzySearch.
- I need to exclude some of the columns as they are producing unwanted results.
- I need these columns to remain searchable so I can continue using them to produce filter buttons.
Search input function
$("#search_keywords").keyup(function (e) {
if(e.which == 13) {
showTable();
}
// Search and draw (below)
});
Search and draw - Option 1 and 2 work
1. DataTables search on columns 13 and 2:
table.column([13,2]).search($(this).val()).draw();
2. FuzzySearch search on whole table:
table.search.fuzzy($(this).val()).draw();
3. I want this option to work but it doesnt:
table.column([13,2]).search.fuzzy($(this).val()).draw();
Error code when using option 3
DataTable_JS.js:181 Uncaught TypeError: table.column(...).search.fuzzy is not a function
at HTMLInputElement.<anonymous> (DataTable_JS.js:181:33)
at HTMLInputElement.dispatch (student-vendor.min.js:1:44187)
at v.handle (student-vendor.min.js:1:40920)
Thank you in advance.
Replies
I added a
fuzzySearch.columns
option to the Fuzzy Search plugin, for example:I made two changes to the code in the
fuzzySearch()
function. First is to get the defined columns:Second is to compare only the cells in the defined columns:
The modified plugin code is in the Javascript tab. My basic testing seems to work.
https://live.datatables.net/paraqipi/1/edit
Note: the columns option supports providing only an array of column indexes to fuzzy search.
Kevin
Amazing work! Thank you for adding that in.
All testing well from this end.
Great addition I reckon
. I've added it into the plug-in. Nice one Kevin.
Allan
@allan I was looking at creating a PR but was unsure what all needed changing and just hadn't got around to asking yet. I figured
features/fuzzySearch/src/dataTables.fuzzySearch.ts
is the only place to change but wasn't sure how to handle this part:Does
ColumnSelector
include all the options atcolumn-selector
withinitial.columns
being an array of indexes representing thecolumn-selector
?Kevin
Yes.
No return type as it isn't a function. It is a TypeScript type. In this case it means that
columns
can be an array of indexes, a string, etc. Resolving it into an array of indexes is done later bycolumns().indexes()
.So... with that said, I realise the error in making it a column selector, rather than just an array of indexes, which I guess is what you were thinking? There isn't a column index resolver from the options at the moment.
I've just been tinkering around with the plug-in, and it needs some work. It doesn't register for
layout
and I don't like how a few things are done in it. It also needs to be updated to how I build plugins, and the CSS pulled into a file.Hah - I thought this was going to be a quick commit! Its going to turn into a rewrite. Doh
Allan
Yes, I thought the definition would be
columns?: array;
. But I don't know TS so not sure if that is valid.LOL, and don't forget the Fuzzy Search blog - just kidding.
Kevin
columns?: array;
would do, althoughcolumns?: number[];
would probably be more appropriate.I was wondering what I should blog about this month - this update might be it...
Allan