0

I have a mover directive with the following html for the list

<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>

So, when I use this directive I can specify my filter-criteria like this

<data-sm:duallist-directive ng-required="false" keep-pristine="true"
                                            unassigned-items-title="'@String.Format(Labels.availableX, Labels.items)'"
                                            unassigned-items="currentItemGroup.unassignedItems"
                                            assigned-items-title="'@String.Format(Labels.assignedX, Labels.items)'"
                                            assigned-items="currentItemGroup.assignedItems"
                                            sortable="false"
                                            filter-criteria="{categoryId:selectedCategoryId}"
                                            selected-item="currentItemGroup.selectedItem">
                </data-sm:duallist-directive>

The problem is with the MoveAllLeft (or MoveAllRight) buttons. They have the following code:

$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;
                };

The problem is that it works against original unfiltered array. Say, if I have 642 items in total and I filtered them by category to only, say, 5, I only want to move these 5 items when I press my button, not all 642 which I don't even see on the screen.

How can I modify my code to get only items which are filtered? Also, I don't have to enter filter-criteria, so it should work correctly when nothing is entered in the filter-criteria.

1 Answer 1

1

I solved the problem - it turned out to be very easy. I added the following code at the top

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);

and now only filtered items are moved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.