1

I have a view with a table that I want to be able to filter what is displayed based on a filtered string entered by the user. The one problem that I am running into is that the fields could be null so my filter does not work.

var quoteNameFilter = function () {

    return function (quotes, filterValue) {
        if (!filterValue) return quotes;

        var matches = [];
        filterValue = filterValue.toLowerCase();
        for (var i = 0; i < quotes.length; i++) {
            var quote = quotes[i];
            if (quote.rfq.toLowerCase().indexOf(filterValue) > -1 ||
                quote.comments.toLowerCase().indexOf(filterValue) > -1 ||
                quote.priority.name.toLowerCase().indexOf(filterValue) > -1 ||
                quote.customer.customerName.toLowerCase().indexOf(filterValue) > -1 ||
                quote.status.name.toLowerCase().indexOf(filterValue) > -1) {

                matches.push(quote);
            }
        }
        return matches;
    };
};

quote.comments could be null, so how do I check if the value is null in this routine?

1 Answer 1

2

Just ensure the quote.comments is a true value using && operator:

(quote.comments && quote.comments.toLowerCase().indexOf(filterValue) > -1) || ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.