0

I am using meanjs to build an application. I am using ng-filter on the tables for filter my data. It works fine the only issue is that i don't want filter on _id field of the collection as by default it searches on all the fields, so I want to exclude _id from the filter. Any way to achieve it?

Thanks in advance.

Priyank
  • 1
  • 1
  • 5
  • You need to create custom filter. – dfsq Sep 13 '15 at 07:39
  • Thanks but in case of custom filter i have to specify all the fields on which i want the search, as mentioned in the post: http://stackoverflow.com/questions/13216115/filtering-by-multiple-specific-model-properties-in-angularjs-in-or-relationship what if i dont want to specify fields i want to exclude _id only? – Priyank Sep 13 '15 at 07:41
  • It's also possible you don't have to specify fields manually, you can iterate over all of them using loop and skip `_id` only. – dfsq Sep 13 '15 at 08:15

2 Answers2

0

Thanks dfsq

Finally achieved the required results:

$rootScope.filterResults = function(queryString){
        return function(results){
            if(queryString)
            {
                var keyList = Object.keys(results);
                for (var i = 0; i <=keyList.length; i++) {
                    if(keyList[i]!='_id' && !angular.isObject(results[keyList[i]]))
                    {

                        if(keyList[i]=='enabled')
                        {
                            if(queryString.toLowerCase()=='enabled' && results[keyList[i]]){
                                return true;
                            }
                            if(queryString.toLowerCase()=='disabled' && !results[keyList[i]]){
                                return true;
                            }
                        }
                        else
                        {
                            if(results[keyList[i]] && results[keyList[i]].toString().toLowerCase().indexOf(queryString.toLowerCase()) != -1)
                                return true;
                        }
                    }
                }
                return false;
            }
            return true;
        }
    };
Priyank
  • 1
  • 1
  • 5
0
    Object.prototype.rid = function() {
        var obj = this;
        obj.id = this._id;
        delete this._id;
        return obj;
    }
  $scope.yourObject.rid();
  • 1
    Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone May 30 '16 at 09:59