john-oc / acute-select

Dropdown List Component for AngularJS - NO LONGER UNDER ACTIVE DEVELOPMENT
MIT License
123 stars 83 forks source link

Search text box - does not show up filtered data after first time successful search... #43

Closed sachinkhot02 closed 9 years ago

sachinkhot02 commented 9 years ago

in the dropdown .. I am able to find data with the search text box only once.. after that it does not filter or search the data with the provided search text..whats the problem i dont understand?

eduardorochas commented 9 years ago

+1

ryletko commented 9 years ago

Hello. I have the same issue. I commented out all lines related to 'previousSearchText' in 'filterData()' and it started working correctly.

If you need temporary workaround it should help:

 function filterData() {

            var itemCount = $scope.allItems.length;

            // If search text is blank OR paging is enabled && current number of items is >= pageSize (or zero)
            if ($scope.searchText === "" || ($scope.settings.pageSize && (itemCount >= $scope.settings.pageSize || itemCount === 0))) {
                // Data needs to be re-loaded.
                $scope.allDataLoaded = false;
            }

            var itemsToFilter = $scope.allItems;

            if ($scope.settings.filterType == "contains") {
                $scope.items = $filter("filter")(itemsToFilter, function (item) {
                    // Check for match at start of items only
                    return item.text.toLowerCase().indexOf($scope.searchText.toLowerCase()) > -1;
                });
            }
            else {
                $scope.items = $filter("filter")(itemsToFilter, function (item) {
                    // Check for match at start of items only
                    return item.text.substr(0, $scope.searchText.length).toLowerCase() === $scope.searchText.toLowerCase();
                });
            }
            // Update indexes
            angular.forEach($scope.items, function (item, index) {
                item.index = index;
            });

            checkItemCount();

            $scope.previousSearchText = $scope.searchText;
            $scope.setListHeight();
        }
john-oc commented 9 years ago

@ryletko - good work finding that workaround. Had a bunch of other changes I needed to commit, but I'll start working on a fix for this tomorrow.

sachinkhot02 commented 9 years ago

@ryletko ..thanks dude..it works.

john-oc commented 9 years ago

This is now fixed.