0

I am using a textarea for searching a table, all in an angular2 application with bootstrap.

My code was searching in one column, now I want the search term to be looked up across two columns, and the user will see all the matched table rows highlighted.

HTML:

<input class="form-control" id="search" [(ngModel)]="searchString" type="text" placeholder="Search by Book ID.." style="float:right;"
  value="">

<tr *ngFor="let books of bookDetails |jobsearch:{ bookId: searchString} : false | paginate: { itemsPerPage: 50, currentPage: p };">

The other column that I want to be searched is 'bookName'.

2
  • 1
    What is the «jobsearch» pipe? You could just write a custom pipe that filters based on your logic Commented Feb 7, 2018 at 8:04
  • 1
    this link may help you: stackoverflow.com/questions/41672578/… Commented Feb 7, 2018 at 8:56

1 Answer 1

0

Custom pipe example:

@Pipe({
    name: 'booksearch'
})
export class BookSearchPipe implements PipeTransform {
    transform(items: Array<any>, filter: {[key: string]: any }): Array<any> {
        return items.filter(item => {
            let noMatch = Object.keys(filter)
            .find(key => item[key] !== filter[key]);

            return !noMatch;
        });
    }
}

Usage:

<tr *ngFor="let books of bookDetails |booksearch:{ bookId: searchString, bookname: searchString }”>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.