• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » Javascript » Angular 4 Tutorial Create Custom Search Filter Pipe In HTML Table

Angular 4 Tutorial Create Custom Search Filter Pipe In HTML Table

By Sigit Prasetya Nugroho ∙ November 14, 2017 ∙ Javascript ∙ Leave a Comment

Share : TwitterFacebookTelegramWhatsapp

I will share how to create custom search filter pipe on angular 4 to fellow beginners like me. The filter feature on the angularJS has been omitted on angular 2 and 4. To create a data filter on angular 4 requires the support of a pipe. You can use a pipe to filter the data in HTML table. Follow this short tutorial

Table of Contents

  • 1 What is a PIPE?
  • 2 Custom search filter pipe angular 4 tutorials for beginner
    • 2.1 Similarly, my tutorial on Angular 4 Tutorial Create Custom Search Filter Pipe In HTML Table may be useful

What is a PIPE?

I will not discuss what a pipe is. All the full explanations of the angular pipe are documented on the official Angular 4 website. In essence, the pipe is the same as the filters on the angularjs, and the pipe has a feature that allows us to transform or convert or format data in real-time. Without the help of pipe, we can not create custom filters on angular 4.

As in previous versions, Angular also provides several built-in Pipes that can be used directly like DatePipe, UpperCasePipe, LowerCasePipe, CurrencyPipe, and PercentPipe. Sometimes we need a Pipe that suits our needs.

In this tutorial will create a custom search to filter data on HTML table

Related Articles :

  • Trick To Redirect New Window Or Tab With Post Method On Angular 5
  • Tutorial To Change Date Format Ng-bootstrap Datepicker Angular 5
  • Tutorial Simple CRUD Angular 5 And Lumen 5.6 For Beginners

Another article: Simple Login Form Angular 4 Tutorial For Beginner

Angular 4 Tutorial Create Custom Search Filter Pipe In HTML Table Min

Custom search filter pipe angular 4 tutorials for beginner

Note: in this tutorial, I use ng-cli generator to create a pipe

Create a new pipe with the following command

1
ng g pipe filterdata

Copy the following code in filterdata.pipe.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { Pipe, PipeTransform } from '@angular/core';
 
@Pipe({
  name: 'filterdata'
})
export class FilterdataPipe implements PipeTransform {
 
  transform(items: any[], value: string, label:string): any[] {
    if (!items) return [];
    if (!value) return  items;
    if (value == '' || value == null) return [];
    return items.filter(e => e[label].toLowerCase().indexOf(value) > -1 );
    
  }
 
}

Do not forget to import the above pipe in app.module.ts (If you use ng-cli generator, pipe automatically added to app.module.ts)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
 
import { AppComponent } from './app.component';
import { FilterdataPipe } from './filterdata.pipe';
 
@NgModule({
  declarations: [
    FilterdataPipe
  ],
  imports: [ ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Example of using pipe above, please add new object and copy the following code in app.component.ts

1
2
3
4
5
6
7
listofstudent = [
          {id:"1", name:"icha",age:"20"},
          {id:"2", name:"denok",age:"23"},
          {id:"3", name:"sri utami",age:"10"},
          {id:"4", name:"mbok darmi",age:"40"},
          {id:"5", name:"jeniffer",age:"30"},
          {id:"6", name:"limbuk",age:"22"}];

Add the following html script in app.component.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<table border =1>
  <thead>
    <tr>
      <th colspan="4">Search :
        <input type="text" [(ngModel)]="queryString">
      </th>
    </tr>
    <tr>
      <th style="width:40px;max-width:40px;">#</th>
      <th style="width:60px;max-width:100px;">Name</th>
      <th style="width:60px;max-width:50px;">Age</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let ex of  listofstudent| filterdata: queryString : 'name' ; let i = index ">
      <td>{{i+1}}</td>
      <td>{{ex.name}}</td>
      <td>{{ex.age}}</td>
    </tr>
  </tbody>
 
</table>

The result of custom search filter pipe angular 4 above will be like the following picture

Angular 4 Tutorial Custom Search Filter Pipe In Html Table

To get the complete project above, please download from the following link

https://seegatesite.com/custom-filter-pipe-angular-4-example/

Another angular 4 tutorial : https://seegatesite.com/tag/tutorial-angular/

Similarly, my tutorial on Angular 4 Tutorial Create Custom Search Filter Pipe In HTML Table may be useful

Another Javascript Related Post :

  • React-Table Not Updating or Refreshing Data, The Solution ?
  • How To Custom React Datepicker In Bootstrap
  • Tutorial Create Simple POS Using ReactJS And Laravel Lumen Part 1
  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • The Using Of Reactstrap And React-Table, Suitable For Beginners
  • Tutorial Create Simple Block UI Using React JS

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) lumen api (4) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (8) Publisher Tips (5) react (6) Reactjs (9) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2022 Seegatesite.com