new: Add new api method to fuzzySearch

Jira Issue DD-2083
pull/527/head
SandyDatatables 3 years ago
parent e2d808c971
commit 1d421d1d70

@ -205,6 +205,8 @@
if(!initial) { if(!initial) {
return; return;
} }
var fromPlugin = false;
// Find the input element // Find the input element
var input = $('div.dataTables_filter input', api.table().container()) var input = $('div.dataTables_filter input', api.table().container())
@ -303,7 +305,9 @@
api.rows().iterator('row', function(settings, rowIdx) { api.rows().iterator('row', function(settings, rowIdx) {
settings.aoData[rowIdx]._fuzzySearch = undefined; settings.aoData[rowIdx]._fuzzySearch = undefined;
}) })
api.search(input.val()) fromPlugin = true;
api.search(input.val());
fromPlugin = false;
} }
// Otherwise perform a fuzzy search // Otherwise perform a fuzzy search
else { else {
@ -319,15 +323,31 @@
settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(searchVal, settings.aoData[rowIdx]._aFilterData, initial) settings.aoData[rowIdx]._fuzzySearch = fuzzySearch(searchVal, settings.aoData[rowIdx]._aFilterData, initial)
}); });
fromPlugin = true;
// Empty the datatables search and replace it with our own // Empty the datatables search and replace it with our own
api.search(""); api.search("");
input.val(searchVal); input.val(searchVal);
fromPlugin = false;
} }
fromPlugin = true;
api.draw(); api.draw();
fromPlugin = false;
} }
} }
var apiRegister = $.fn.dataTable.Api.register;
apiRegister('search.fuzzy()', function(value) {
if(value === undefined) {
return input.val();
}
else {
input.val(value);
triggerSearchFunction({key: 'Enter'});
return this;
}
})
input.off(); input.off();
// Set listeners to occur on toggle and typing // Set listeners to occur on toggle and typing
if(toggle) { if(toggle) {
@ -390,6 +410,12 @@
} }
} }
api.on('search', function(){
if(!fromPlugin) {
input.val(api.search());
}
})
// Always add this event no matter if toggling is enabled // Always add this event no matter if toggling is enabled
input.on('input keydown', triggerSearchFunction); input.on('input keydown', triggerSearchFunction);
}) })

Loading…
Cancel
Save