What is the method for creating pipes that filter multiple columns?

My pipe is designed to work exclusively for the "name" column and not for the author anymore.

transform(items: Book[], filter: Book): any {
    if (!items || !filter) {
        return items;
    }

    // Filter items array; keep items that match and return true, filtering out anything false

    return items.filter((item) => item.Nazwa.indexOf(filter.Nazwa) || item.Autor.indexOf(filter.Autor)  !== -1)

}

}

Input data:

filterargs = { Nazwa: "", Autor: "" }

Answer №1

Do you need help filtering multiple book arguments? One way to achieve this is by passing multiple values to the pipe transform function as shown below:

<div *ngFor="let book of books | customizeFilter : argument1 : argument2">
    ...
</div>

In your custom pipe class, you can implement the logic like this:

export class CustomizeFilter implements PipeTransform {
   transform(items: Book[], argument1: any, argument2: any): any {
       // add your filtering logic here
   }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to declare a collection of objects in TypeScript?

Need assistance with TypeScript - Can anyone help? I'm having trouble deciphering the error message in relation to the code snippet below. My goal is to create an array of objects, but it doesn't seem to be working as expected. interface FieldC ...

Connecting two fields with a line on click in AngularJS

In the top section, there are 10 fields and in the bottom section, there are another 10 fields. I want to be able to connect two fields with a line when they are clicked (one from the top section and one from the bottom section). This connection should app ...

Angular Single Page Application Development

Currently exploring the implementation of a single-page application in Angular.js Came across a helpful demo at http://scotch.io/demos/angular-single-page-routing which seems suitable for my needs. However, while browsing through http://scotch.io/demos ...

AngularJS Input Validation: Ensuring Data Integrity

Currently, I have two textbox controls named "Low" and "High". The High field should not allow a value lower than that of Low. To achieve this validation, the following code snippet was implemented: <input id="txtLow" class="txtCell" ng-model='dat ...

Flow error: Unable to access the value of this.props.width as the property width is not defined in T

In my React Native project, I am utilizing Flow for type checking. For more information, visit: I currently have two files named SvgRenderer.js and Cartoon.js where: Cartoon extends SvgRenderer Below is the source code for both of these files: SvgRend ...

Refine the observable data

Trying to filter a list of items from my Firebase database based on location.liked === true has been a challenge for me. I've attempted using the traditional filter array method but have not had success. Can anyone suggest an alternative method to acc ...

Why won't my files upload with AngularJS?

$scope.uploadFiles = function () { //debugger; var request = { method: 'POST', url: 'http://example.com/upload/', data: formdata, headers: { ...

What are the recommended techniques for utilizing prototypal and prototype-based inheritance in modern JavaScript (ES6) and TypeScript?

Some older discussions on Javascript prototypal inheritance & delegation can be found below: Benefits of prototypal inheritance over classical? classical inheritance vs prototypal inheritance in javascript I am curious about the current (2018) recom ...

Custom search filter in ng-grid using a customized cellTemplate

I am facing an issue with the ng-grid search filter on a column that references a cellTemplate. In my data object, there are multiple fields. One of these fields is an array and I have used cellTemplate to create a div with ng-repeat in order to display t ...

Import a fixed JSON document in Webpack

In the code I have, there is a construction that looks like this: var getMenu = function () { return window.fetch("portal/content/json/menu.json").then(function (data) { return data.json(); }); }; I attempted the following in my webpack.c ...

Using jQuery within an Angular Controller: The specific function $(...).overhang is not recognized in this context

Recently, I decided to integrate overhang.js into my application because of its appealing alert messages. Initially, it seemed like a simple task... All I needed to do (or so I thought) was replace the line in my controller, alert("An HTTP request has be ...

Utilizing the MapToIterable Angular Pipe with TypeScript

Exploring the implementation of a pipe in Angular. Discovered that ngFor doesn't work with maps, prompting further research to find a solution. It seems that future features may address this issue, but for now, utilizing a mapToIterable pipe is the re ...

What could be causing the conditional div to malfunction in Angular?

There are three conditional div elements on a page, each meant to be displayed based on specific conditions. <div *ngIf="isAvailable=='true'"> <form> <div class="form-group"> <label for ...

Tips for storing an array of ReplaySubjects in a single variable in an Angular application

I am looking to store several ReplaySubjects in a single array. Here is my code: public filteredSearch: ReplaySubject<any[]> = new ReplaySubject(1); this.filteredSearch[id].next(filter(somedata)); When I run this code, I encounter an error saying ...

Mastering the Art of Unit Testing with Angular Extensions

I am currently working with a controller that uses angular extend. How can I go about testing angular extend in this scenario? angular.module('conditionmonitor').controller('mapController', ['$scope', '$http', &apo ...

What is the process for importing a component at a later time?

I am attempting to import components with a delay in a seamless manner. My goal is to import the components discreetly so that they load smoothly in the background while viewing the homepage. I experimented with lazy loading, but found that it caused dela ...

Obtaining the token using CURL with jhipster oauth: A step-by-step guide

Currently experimenting with jhipster to develop a new project featuring oauth2 authentication. The sample project is functioning smoothly, allowing me to log in using the angularjs interface. Struggling when attempting to fetch an access_token via CURL in ...

What is the process of destructuring an array containing objects?

Examining this JSON structure: { "Person": { "UID": 78, "Name": "Brampage", "Surname": "Foo" }, "Notes": [ { "UID": 78, "DateTime": "2017-03-15T15:43:04.4072317", "Person": { ...

Navigating through a large array list that contains both arrays and objects in Typescript:

I have an array containing arrays of objects, each with at least 10 properties. My goal is to extract and store only the ids of these objects in the same order. Here is the code I have written for this task: Here is the structure of my data: organisationC ...

Struggling to Add angular-websocket to a MeanJS v0.4.1 Application: Dealing with an 'Unknown Provider' Error

I'm encountering some challenges while using angular-websocket in a controller within my MeanJS project. The version of MeanJS I’m working with is v0.4.1. To begin, I installed it by running: bower install angular-websocket --save This creat ...