Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keep search input at the top of list view in ionic framework

I am new to Ionic Framework, so I am experimenting with it now. On one of my page, I have a search input followed by a list, which looks like this:

enter image description here

When I scroll up, the search field is scrolling up with the list view. Is it possible to keep the search field fixed at the top whilst scrolling?

This is my HTML markup so far:

<ion-view view-title="Force">
  <ion-content>
    <label class="item item-input">
      <i class="icon ion-search placeholder-icon"></i>
      <input type="text" placeholder="Search Force" data-ng-model="searchForce">
    </label>
    <div class="list">
      <ion-item class="item-icon-right" ng-repeat="force in forces | filter:searchForce" type="item-text-wrap" href="#/tab/force/{{force.id}}">
        {{force.name}}
        <i class="icon ion-chevron-right icon-accessory"></i>
      </ion-item>
    </div>
  </ion-content>
</ion-view>
like image 947
Latheesan Avatar asked Apr 29 '15 15:04

Latheesan


1 Answers

You can use a sub-header for this:

 <ion-header-bar class="bar-light bar-subheader">
      <input type="text" placeholder="Search Force" data-ng-model="searchForce">
      <button ng-if="searchForce.length"
              class="button button-icon ion-android-close input-button"
              ng-click="clearSearch()">
      </button>
</ion-header-bar>

Codepen demo

Also see this post for some alternatives: http://forum.ionicframework.com/t/how-to-make-search-bar-sticky/20721

like image 70
brandyscarney Avatar answered Oct 27 '22 22:10

brandyscarney