Bug in Criteria.stringConditions.ends.search function of searchBuilder
Bug in Criteria.stringConditions.ends.search function of searchBuilder

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Original code in dataTables.searchBuilder.js:
Criteria.stringConditions = {
'ends': {
conditionName: 'Ends With',
init: Criteria.initInput,
inputValue: Criteria.inputValueInput,
isInputValid: Criteria.isInputValidInput,
search: function (value, comparison) {
return value.toLowerCase().indexOf(comparison[0].toLowerCase()) === value.length - comparison[0].length;
}
}
The search function is not correct.
function search(value, comparison) {
return (value.toLowerCase().indexOf(comparison[0].toLowerCase()) === value.length - comparison[0].length);
}
result = search('ab', ['abc']);
console.log(result);
The result is true
, but should be false
.
The function should be:
function search(value, comparison) {
return (value.toLowerCase().indexOf(comparison[0].toLowerCase()) === value.length - comparison[0].length)
&& (value.length - comparison[0].length != -1);
}
Or:
function search(value, comparison) {
return value.toLowerCase().endsWith(comparison[0].toLowerCase());
}
This discussion has been closed.
Replies
Hi @Mikea ,
Thanks for pointing this out, it appears to be something that we have overlooked. I've raised an issue internally (DD-1705 for my reference) and will report back here when there is an update.
Thanks,
Sandy
Hi @Mikea ,
That should be the issue fixed now as you can see at this example.
Thanks again for pointing this out to us,
Sandy
Hi @sandy,
OK.