Bug in Criteria.numFmtConditions.>.search function of searchBuilder

Bug in Criteria.numFmtConditions.>.search function of searchBuilder

MikeaMikea Posts: 8Questions: 2Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Original code in dataTables.searchBuilder.js:

Criteria.numFmtConditions = {
    '>': {
        conditionName: 'Equals',
        init: Criteria.initSelect,
        inputValue: Criteria.inputValueSelect,
        isInputValid: Criteria.isInputValidSelect,
        search: function (value, comparison) {
            var val = value.replace(/[^0-9.]/g, '');
            var comp0 = comparison[0].replace(/[^0-9.]/g, '');
            return +val > +comp0;
        }
    }
}

The search function is not correct.

function search(value, comparison) {
    var val = value.replace(/[^0-9.]/g, '');
    var comp0 = comparison[0].replace(/[^0-9.]/g, '');
    return +val > +comp0;
}
result = search('-3%', ['2%']);
console.log(result);

The result is true, but should be false.
Suggest to use Numeral.js (http://numeraljs.com/) to compare.

function search(value, comparison) {
    var val = numeral(value).value();
    var comp0 = numeral(comparison[0]).value();
    return val > comp0;
}
result = search('-3%', ['2%']);
console.log(result);

The result is false.

This question has an accepted answers - jump to answer

Answers

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @Mikea ,

    Thanks for pointing this out, it appears to be something that we have overlooked. I've raised an issue internally (DD-1704 for my reference) and will report back here when there is an update.

    Thanks,
    Sandy

  • sandysandy Posts: 913Questions: 0Answers: 236

    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

  • MikeaMikea Posts: 8Questions: 2Answers: 0
    edited October 2020

    Hi @sandy
    Not fixed in Criteria.numFmtConditions.between and Criteria.numFmtConditions.!between.

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi @Mikea,

    Apologies, poor show from me to miss those. They are fixed now.

    Thanks,
    Sandy

This discussion has been closed.