Search code examples
angularjssmart-table

How to identify if search criteria is changed in angularjs smart-table?


I am using angularjs smart-table to display data on a web page. I am using certain fields to filter the data and display. There is also pagination on the table. Everything is working perfect. I have a checkbox on the table header for selectall functionality and another checkbox at each row level. I have to clear checkboxes (if they are checked) whenever there is any change in search criteria. I cannot think of how I can do it. Any ideas on how I can achieve this ?


Solution

  • .controller('MyController', ['$scope', funciton($scope){
    
    $scope.data = {}; // probably a JSON object
    
    $scope.reset = function(){
      scope.data.row.forEach(function(el){
         el.checkbox = false;
      });
    };
    
    }])
    
    <input type="text" ng-change="reset()"/>
    
    <div ng-repeat="item in data track by $index">
       <!-- Items -->
    </div>
    

    Note: You can also put this inside a directive, wich is the fancy of angular.

    .directive('clear', function(){
      return {
         restrict : 'A',
         require : 'ngChange',
         link : function(scope, element, attrs, ngChangeCtrl){
             //Do your stuff with ngChange controller 
         }
      };
    });
    
    <input type="text" clear/>