Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll at top of the page in ionic

currently i am working in ionic framework on javascript and angular-js i just put the search box and render list of customer but suppose in first attempt i can search with 'a' it shows all item which having alpha 'a' but the problem is when i scroll down to see the search result list and at the bottom if i want to search with 'd' this time it gives result but at the top of the page but my scroll is at the bottom of the page. So to solve the above problem i want set scroll position at the top of the page when search query is empty and display all customer so what should i do to solve this problem

thanks in adv..

like image 630
Rohit Deshmukh Avatar asked Sep 09 '15 15:09

Rohit Deshmukh


People also ask

What is virtual scroll in Ionic?

Virtual Scroll displays a virtual, "infinite" list. An array of records is passed to the virtual scroll containing the data to create templates for. The template created for each record, referred to as a cell, can consist of items, headers, and footers.


2 Answers

You can try :

$ionicScrollDelegate.scrollTop(); 

http://ionicframework.com/docs/api/service/$ionicScrollDelegate/

like image 159
Grégoire Motot Avatar answered Sep 22 '22 20:09

Grégoire Motot


For Ionic 2 and higher use the scrollToTop() method on the content class.

page.html

<ion-content>   Add your content here! </ion-content> 

page.ts

import { Component, ViewChild } from '@angular/core'; import { Content } from 'ionic-angular';  @Component({...}) export class MyPage{   @ViewChild(Content) content: Content;    scrollToTop() {     this.content.scrollToTop();   } } 

See http://ionicframework.com/docs/api/components/content/Content/#scrollToTop

like image 43
Pavel Chuchuva Avatar answered Sep 20 '22 20:09

Pavel Chuchuva