import {Component, ViewChild} from '@angular/core'; import {DatatableComponent} from '../../src/components/datatable.component'; @Component({ selector: 'filter-demo', template: `

Client-side Search and Filtering Source

` }) export class FilterBarComponent { rows = []; temp = []; columns = [ { prop: 'name' }, { name: 'Company' }, { name: 'Gender' } ]; @ViewChild(DatatableComponent) table: DatatableComponent; constructor() { this.fetch((data) => { // cache our list this.temp = [...data]; // push our inital complete list this.rows = data; }); } fetch(cb) { const req = new XMLHttpRequest(); req.open('GET', `assets/data/company.json`); req.onload = () => { cb(JSON.parse(req.response)); }; req.send(); } updateFilter(event) { const val = event.target.value; // filter our data const temp = this.temp.filter(function(d) { return d.name.toLowerCase().indexOf(val) !== -1 || !val; }); // update the rows this.rows = temp; // Whenever the filter changes, always go back to the first page this.table.offset = 0; } }