could someone help me with issue?nf n I have array of objects which is displayed in table and I have search. Every object is one row in table. The main problem is in array. We can modify it at any time (can add new rows, delete existing rows and change value in table) , even if we search something.
Now I have something like this:
$scope.$watch( 'search', function() {
if($scope.search!== "") {
if(! $scope.initArray.length) {
$scope.initArray= $scope.array;
}
$scope.array= $filter('filter')($scope.initArray, function(item) {
return item.name1.indexOf($scope.search) > -1 ||
item.name2.indexOf($scope.search) > -1 ||
item.name3.toLowerCase().indexOf($scope.search) > -1;
});
} else {
$scope.array= $scope.initArray;
}
});
As you can see, I use two arrays. Everything is good, but when I want to change $scope.array I have to change $scope.initArray. And it causes a lot of issues.
For example, table has 3 rows. Every row consist of 3 colomns. I search something and it finds just one row (search has to find value at least in one of colomn). After that I add new row. It displays in table if it contains value I'm searching for. If we clear search field, all data is displayed back. For this correct behavior, I have to do a lot of equal manipulation with $scope.initArray and $scope.array. If I use just one array, after searching table contains incorrect data.
Is there a way where I can use just one array?
$scope.array I pass it to UI.
$scope.initArray it's initial data (before search)