I solved the problem - turned out to be very easy:
var filteredData ;
if ($scope.filterCriteria)
filteredData = $filter('filter')($scope.unassignedItems, $scope.filterCriteria);
else
filteredData = $scope.unassignedItems;
var unassignedItems = filteredData.slice(0);
var smItems = filteredData.slice(0);
>Hi everybody,
>
>I have the following directive (html):
>
>
>@using Siriusware.Resources;
><div class="form-horizontal">
> <div class="col-xs-5 pull-left">
> <div class="form-group">
> <label class="control-label">{{unassignedItemsTitle}}</label>
> <div>
> <select class="select-list" multiple
> ng-model="unassigned"
> name="unAssignedList"
> data-no-dirty-check
> ng-options="unassignedItem.descrip for unassignedItem in unassignedItems | orderBy:'descrip' | filter: filterCriteria"></select>
> </div>
> </div>
> </div>
>
> <div class="col-xs-2 pull-left" style="text-align: center; padding: 25px;">
> <button ng-click="moveRight(unassigned)" class="btn btn-block"><i class="fa fa-angle-right icon-1x"></i></button>
> <button ng-click="moveRightAll()" class="btn btn-block"><i class="fa fa-angle-double-right icon-1x"></i></button>
> <button ng-click="moveLeft(assigned)" class="btn btn-block"><i class="fa fa-angle-left icon-1x"></i></button>
> <button ng-click="moveLeftAll()" class="btn btn-block"><i class="fa fa-angle-double-left icon-1x"></i></button>
> </div>
>
> <div class="col-xs-5 pull-left">
> <div class="form-group">
> <div>
> <label class="control-label">{{assignedItemsTitle}} </label>
> <span class="pull-right" ng-show="sortable && assigned != null && assignedItems.length > 1 ">
> <a class="badge" ng-click="moveUp(assigned)" data-toggle="tooltip" title="@Labels.moveUp"
> sm:blankanchor><i class="fa fa-angle-up icon-1x"></i></a>
> <a class="badge" ng-click="moveDown(assigned)" data-toggle="tooltip" title="@Labels.moveDown"
> sm:blankanchor><i class="fa fa-angle-down icon-1x"></i></a>
> </span>
> </div>
> <div>
> <select class="select-list"
> ng-change="onChanged(assigned)"
> multiple
> data-no-dirty-check
> ng-model="assigned"
> name="assignedList"
> ng-options="assignedItem.descrip for assignedItem in assignedItems| orderBy: 'SortOrder' | filter: filterCriteria">
> </select>
> </div>
> </div>
> </div>
></div>
>
>So, as you can see, I can specify the filter-criteria and the items will be properly filtered. Ok, so far so good.
>
>Now, I have the following code for the MoveRightAll (and similar for MoveLeftAll):
>
>
>$scope.moveRightAll = function() {
> var unassignedItems = $scope.unassignedItems.slice(0);
> var smItems = $scope.unassignedItems.slice(0);
>
> angular.forEach(smItems, function (value, key) {
> $scope.assignedItems.push(value);
> removeItem(unassignedItems, value);
> });
> $scope.unassignedItems = unassignedItems;
> if (!$scope.keepPristine)
> $scope.form.$setDirty();
>
> $scope.assigned = null;
> };
>
>So, the problem here that this code doesn't respect the filter. Say, I filtered items by department and category and then clicked on move all button, all 642 items are getting moved instead of just a few from that category.
>
>So, I just want to get the filtered list at the top if I have something in the $scope.filterCritera.
>
>Thanks in advance.
If it's not broken, fix it until it is.
My Blog