Search code examples
angularjsangular-filters

AngularJS: searching data client side by custom filter


i am learning angular. so i am not good in angular. i am showing data in tabular format with the help of ng-repeat. i have one dropdown and textbox for filter data showing by ng-repeat. fields name are populated in dropdown. so user will select field name and put corresponding value in textbox and search will perform accordingly and data will be shown.

my code is working partially. basically some kind of problem is there in SearchList function. the problem is when trying to search by id then SearchList is not working properly. so looking for help. what to fix in the code. my js fiddle https://jsfiddle.net/tridip/rnoo3bqc/6/

$scope.SearchList = function(row) {

    if ($scope.selectedFieldName && $scope.searchText) {
      var propVal = row[$scope.selectedFieldName.toLowerCase()];
      if (propVal) {
        return propVal.toUpperCase().indexOf($scope.searchText.toUpperCase()) > -1;
      } else {
        return false;
      }
    }
    return true;    
  };

working version url

https://jsfiddle.net/tridip/rnoo3bqc/8/


Solution

  • You need to convert the id's from number to string, e.g. by concatenating an empty string:

    var propVal = row[$scope.selectedFieldName.toLowerCase()] + '';