ionic-filter-bar icon indicating copy to clipboard operation
ionic-filter-bar copied to clipboard

Make a search bar - Not only filter given items

Open filoozom opened this issue 10 years ago • 3 comments

Hello,

I'm currently using your plugin for an Ionic project, and I really like it! I'm using your plugin to filter a given set of items, but now I'd like to perform a search on a database.

For now, I'm using something like this:

$scope.events = var events = Events.getFuture();

$scope.showFilterBar = function () {
  filterBarInstance = $ionicFilterBar.show({
    filterProperties: 'name',
    items: Events.all(),
    update: function (filteredItems) {
      $scope.events = filteredItems;
    },
    cancel: function () {
      $scope.events = events;
    }
  });
};

So basically I'm displaying all future events on my page, but do a search on all events, and when the filter bar is canceled I just put my old list of events back. This is working for now, but my events list won't stop growing, and I don't think I'll be able to afford to load all events in memory just to filter them in the future.

Would it be possible to create an options in $ionicFilterBar.show that would take filterText as parameter and return the list of items that match the search term? So that I could have something like:

$scope.showFilterBar = function () {
  filterBarInstance = $ionicFilterBar.show({
    search: function (filterText) {
      $scope.events = Events.searchByName(filterText);
    },
    cancel: function () {
      $scope.events = events;
    }
  });
};

I don't think that this is possible with the current implementation. Thanks!

filoozom avatar Aug 28 '15 21:08 filoozom

Would something like #35 work?

filoozom avatar Aug 28 '15 22:08 filoozom

I also have a similar requirement to do search by calling a backend api instead of filtering items from an array. But I don't know how #35 would work because search results don't necessarily come back immediately. Search should take a callback or return a promise in my opinion.

5amfung avatar Sep 02 '15 09:09 5amfung

+1

jeandat avatar Feb 12 '16 10:02 jeandat