need to write code for two select box to filter on click.
-
- import { Pipe, PipeTransform } from '@angular/core';
- import { DatePipe } from '@angular/common';
- @Pipe({
- name: 'filterMonthYear'
- })
- export class FilterMonthYearPipe implements PipeTransform {
- transform(value:any, startmonth: string, endmonth : string): any{
- if(value.length === 0){
- return value;
- }
- const resultArray = [];
- console.log(startmonth);
- console.log(endmonth);
- var from_date = Date.parse(startmonth);
- var to_date = Date.parse(endmonth);
- for(const item of value)
- {
- if(item.startmonth > from_date && item.endmonth < to_date) {
- resultArray.push(item);
- }
- };
- return resultArray;
- }
- }
html
- <label>Start Month</label>
- <select class="form-control" name="selectedstart" [(ngModel)]="selectedstartmonth">
- <option >Choose..</option>
- <option *ngFor="let table of TableData" >{{table.startmonth}}</option>
- </select>
- <p>{{selectedstart}}</p>
- </div>
- <div class="col-xs-6 col-sm-6 col-md-6">
- <label>End Month</label>
- <select class="form-control" name="selectedend" [(ngModel)]="selectedendmonth">
- <option >Choose..</option>
- <option *ngFor="let table of TableData">{{table.endmonth}}</option>
- </select>
- <button class="btn btn-primary" type="submit"
- (click)="getFilteredDate(startmonth.value, endmonth.value)">
- Submit
- </button>
- <tr *ngFor="let table of TableData | filterMonthYear:selectedstartmonth:selectedendmonth">
- <td class='td-group1'>{{table.description}}</td>
- <td>{{table.money}}</td>
- <td>{{table.test}}</td>
- <td>{{table.bbb}}</td>
- </tr>
component.ts
- getFilteredDate(startmonth, endmonth){
-
- }