djett41 / ionic-filter-bar

Filter Bar plugin for the Ionic Framework
MIT License
362 stars 112 forks source link

Set filter programmatically? How? #59

Open flagsoft opened 9 years ago

flagsoft commented 9 years ago

Is it possible right now to set the filter via programming?

Is know there is a "filterText" which gives my the text entered char by char in the search text field. But how can I set this programmatically?

-> For example, if I have a linke / button to push to set the filter to "test1"

User interface:

+========================+
 [ test 1                 (x)   ]  <- ionic-filter-bar 

+-------------------------+

   [ Button "test 1" ] ->   open filter bar and set filtertext to "test 1"
   [ Button "test 2" ] ->   open filter bar and set filtertext to "test 2"
   [ Button "test x" ] ->   open filter bar and set filtertext to "test x"
+========================+

So it should be possible to pre programm a link (button) with for example:

Link:

/www/index.html#/tab/search?filterText="test 1"

So when someone presses the button it opens ionic-filter-bar with "test 1" as a filter text and do the filtering as if one typed in the text.

  $scope.showFilterBar = function () {
    filterBarInstance = $ionicFilterBar.show({
      delay: 1000,
      cancelText: "<i class='ion-ios-close-outline'></i>",
      items: $scope.items,
      update: function (filteredItems, filterText) {
        $scope.items = filteredItems;
        if (filterText) {
          console.log('*** filterText:', filterText);
        }
      }
    });
  };