0

I've been working on this Degree Program finding tool that uses AngularJS. What I'm trying to build is an eCommerce style sidebar filtering options. I have gotten Degree Levels and a free-form search field working together, but I haven't been able to get the Locations Offered filter to work in conjunction with the radio buttons.

This is my controller:

    $scope.search = function (row) {
    return (
        angular.lowercase(row.DPNAME).indexOf(angular.lowercase($scope.query) || '') !== -1 ||
        angular.lowercase(row.DPCAREERS).indexOf(angular.lowercase($scope.query) || '') !== -1 ||
        angular.lowercase(row.DPCONCENTRATIONS).indexOf(angular.lowercase($scope.query) || '') !== -1
    );
};
$scope.DLsearch = function (row) {
    return (
        row.DPDEGREELEVEL.indexOf($scope.qDegreeLevel || '') !== -1
    );
};

$scope.LOCsearch = function (row) {
    return (
        row.DPONCAMPUSMESA == 'Yes'
    );
};

And its that last filter that isn't quite working right. If you replace "DPONCAMPUSMESA" with any of the other location fields (such as DPONCAMPUSLISLE or DPNONTRADNMCALCENTRALIL) it does filter the data correctly. But I haven't been able to connect it to the radio buttons.

I'm also open to a different approach to the filters.

Here is the CodePen I've been working on: http://codepen.io/ksherman/pen/yYqGgx?editors=101 And if you're interested in the JSON structure: http://www.jsoneditoronline.org/?id=5145f3cca9dd9d5e5eaef2e39e2b2808

1 Answer 1

1

I've opened your CodePen and last filter works exactly how it's written - leaves only two rows for which condition is met (row.DPONCAMPUSMESA == 'Yes'). To make it more generic try:

$scope.LOCsearch = function (row) {
    if (!$scope.qLocation) {
        return true; // no filter or 'All' option
    } else {
        return row[$scope.qLocation] == 'Yes';
    }
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I knew I was really close, I just couldn't figure out how to use the qLocation variable. So it was the row[...] that answered it for me! Whew, still more javascript to learn.

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.