hello everyone ! am using storage to store my json files.
my .JSON file looks like this.
hymn.JSON :
[{
"songno": "1.",
"title": "அகோர கஸ்தி பட்டோராய்"
},
{
"songno": "2.",
"title": "அஞ்சாதிரு, என் நெஞ்சமே"
},
{
"songno": "3.",
"title": "அதிகாலை இயேசு வந்து"
},
{
"songno": "4.",
"title": "அதிசயங்களை"
},
{
"songno": "5.",
"title": "அநாதியான கர்த்தரே"
}
]
home.html :
<ion-searchbar (ionInput)="getItems($event)" aria-placeholder="search"></ion-searchbar>
Home.TS :
export class HomePage {
items : any = [] ;
key : string = "items";
filterItems: any;
constructor(public navCtrl: NavController,private storage: Storage,public http:HttpClient) {
this.importJson();
}
importJson(){
let data:Observable <any> = this.http.get('assets/json/hymn.JSON');
data.subscribe(result =>{
this.items = result;
this.storage.set(this.key, JSON.stringify(this.items));
this.storage.get(this.key).then((val) => {
if(val!=null && val!= undefined){
this.filterItems = this.items;
}
});
});
}
intializeItems(){
this.importJson();
}
getItems(ev) {
// Reset items back to all of the items
this.intializeItems();
var valu = ev.target.value;
if (valu && valu.trim() != '') {
this.items = this.items.filter((item) => {
return (item.songno.toLowerCase().indexOf(valu.toLowerCase()) > -1) ||
(item.title.toLowerCase().indexOf(valu.toLowerCase()) > -1);
})
}
}
The problem is the filer works .
For Eg : If i type 23 in search bar ,the 23rd ID appears but when i clear the 23 back the whole list vanishes showing only the 23rd ID . Thanks guys. Hope i get a solution here for this