S
S
semolex2015-05-09 00:27:24
Angular
semolex, 2015-05-09 00:27:24

How to filter a table using checkboxes on nested object fields using AngulaeJS?

I need to filter a table with an array of objects by some parameters. And you need to do this with the help of checkboxes / radios, etc.
Here is an example of objects:

{
    "_id": "24b87678e363397ec9e89d61bdde5d90",
    "priority": 1,
    "updated": "2015-04-27T15:30:36Z",
    "name": "angelus",
    "active": true,
    "options": {
        "disable_work": true,
        "remote": yes
}
    },

{
    "_id": "24b87678e363397ec9e89dadbdde5d90",
    "priority": 3,
    "updated": "2015-04-27T15:30:36Z",
    "name": "raminus",
    "active": true,
      }

Here's how I'm trying to filter it all:
controller.js:
$scope.itemFilterForm = {};
view:
<input type="checkbox" ng-true-value="true"  ng-false-value="" ng-model='itemFilterForm.options.disable_work'>

Well, I put a filter on the object in ng-repeat.
So, here's the problem:
When I put a checkbox, everything is filtered as it should. But when I shoot, only those objects are visible, which have `options` properties and does not show the rest. How to make it so that when the checkbox is unchecked, all objects are shown?
ps There can be several such checkboxes, each of which is responsible for one of the parameters from the `options` property, which not all objects have.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kano, 2015-05-09
@Kano

Referring to the angularjs documentation https://docs.angularjs.org/api/ng/filter/filter
we find that the filter filter can take three parameters
1. data array
2. expression - string, object or function (in your case, this is a form object)
3. comparison function - this is what we need to define in our scope
This function takes 2 parameters, the first is the list element, the second is the object of your form. This function returns true, false or undefined. You can define the logic for comparing these two parameters yourself, here is an example stackoverflow.com/questions/21199759/angularjs-fil...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question