mercredi 1 juin 2016

How to filter table with multiple checkboxes

I'm using angularjs with html code in this case. I also use smart-table for the table. Here is my controller .js file :

getStatut.js :

app.controller('GestioncasCtrl', ['$scope', 'DataTicketFactory', function ($scope, DataTicketFactory) {
    $scope.search = [];
    $scope.data_server = [];


    DataTicketFactory.getData().then(function (response) {
        $scope.data_server = response.data;
        $scope.search = response.data;

    });

    $scope.getStatut = function (idstatut, value, data_server2) {
        var ret = [];
        if (idstatut === true)
        {
           for (var it = 0; it < data_server2.length; it++) {
                if (data_server2[it].statut_cas_id_statut === value)
                {

                    ret.push(data_server2[it]);
                }
            }
            $scope.data_server = ret;
        } else if (idstatut === false) {
            $scope.data_server = $scope.search;
        }
    };
}]);

HTML file with checkboxes :

 <label ng-class="[getClasscolor(0)]"><input ng-change="getStatut(data.statut_cas_id_statut1, 0, displayCollection)" ng-model="data.statut_cas_id_statut1" value="0" type="checkbox" >&nbsp;Opened&nbsp;</label>
  <label ng-class="[getClasscolor(2)]"><input ng-change="getStatut(data.statut_cas_id_statut2, 2, displayCollection)" ng-model="data.statut_cas_id_statut2" value="2" type="checkbox">&nbsp; Waiting&nbsp;</label>

Table html in same file :

<tr ng-class="[getClasscolor(data.statut_cas_id_statut)]" ng-repeat="data in displayCollection" st-select-row="data" st-select-mode="single">
<td  width="90px"> </td>
<td  width="100px"></td>
<td  width="200px"></td>
<td  width="200px"></td>
<td  width="200px"> </td>
<td  width="100px"> </td>
<td  width="100px"><img id="imglink"  ng-src="../../images/icon_priority_.png" alt=""></td>
</tr>

The code still work but only with 1 status.

I want to filter with multiple choices. If i check "Opened" and "Waiting" checkboxes, the table has to display all the objects with statut_cas_id_statut1 = 0 AND statut_cas_id_statut2 = 2.

Any idea to perform my code for the purpose ?




Aucun commentaire:

Enregistrer un commentaire