Filtering through an array object with PrimeNG

Is it feasible to utilize an array of objects for filtering data in a table?

I'm currently using Angular 6 and PrimeNG 7.

This is how my p-table appears:

<p-table #table class="ui-table ui-table-responsive" [value]="arrays"  [columns]="cols" >
    ...
    <div class="col-xl-4">        
    <i class="fa fa-search" style="margin:4px 4px 0 0"></i>
    <input type="text" pInputText size="50" placeholder="Search" (input)="table.filter($event.target.value, cols['sort'], 'contains')" style="width:auto">
    </div>
    ...
<p-table>

I prefer using filter() over globalFilter() as I need to specify the field for filtering.

The columns in my table are defined as follows:

this.cols = [
  { field: 'number', sort: 'number', header: 'The number' },
  { field: 'type', sort: 'type', header: 'The type' },
  { field: 'place', field2: 'placeName', sort: 'place.placeName', header: 'The place'},
  { field: 'city', field2: 'cityName',  sort: 'city.cityName', header: 'The city' },
  ...
  ...
];

Unfortunately, my current filter implementation is not functioning correctly.

Answer №1

Make sure to include the column for col.field when passing your column.

(input)="dt.filter($event.target.value, col.field, col.filterMatchMode)"

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

The 'formGroup' property cannot be bound as it is not recognized as a valid property of 'form' in Angular 7

I tried implementing a login feature using web API with Angular 7, but encountered an error when using <form [formGroup]="loginForm" (submit)="loginFormSubmit()">. What could be causing this issue? https://i.sstatic.net/3M2a5.jpg login.component.ht ...

What could be causing the malfunction of the constructor of these two root services?

Below are two primary root services: Service 1: @Injectable({ providedIn: 'root', }) export class DataService { private data$ = new BehaviorSubject([]); public dataObs$ = this.data$.asObservable(); constructor(private http: HttpClient) ...

Error message: Invalid form submission in Django REST framework

I am currently working with a model, model form and view structured in the following way: @api_view(['POST']) def addCigar(request): print(request.POST) form = CigarForm() if request.POST: form = CigarForm(request.POST) ...

Adding typing to Firebase Functions handlers V2: A step-by-step guide

Here's a function I am currently working with: export async function onDeleteVideo(event: FirestoreEvent<QueryDocumentSnapshot, { uid: string }>): Promise<any> { if (!event) { return } const { disposables } = event.data.data() ...

TypeScript introduces a flexible generic type, Optional<T, Props>, allowing customized props for a specific

In my attempt to develop a type called Optional<T, TProps>, where T represents the initial type and TProps is a union type of properties that need to be optional. As an illustration: type A = Optional<{a: string, b: string}, 'a'&g ...

Unable to access res.name due to subscription in Angular

Right now, I am following a tutorial on YouTube that covers authentication with Angular. However, I have hit a roadblock: The code provided in the tutorial is not working for me because of the use of subscribe(), which is resulting in the following messag ...

Creating an Angular 2 component library that is compatible with both webpack.js and system.js: A guide

This is my first venture into creating an Angular 2 library. So far, it consists of a collection of components. I am aiming to make this library compatible with both Webpack and SystemJS. I have successfully written the code for the first component to be c ...

I cannot access the 'isLoading' state in React Query because it is undefined

Since updating to the latest version of react query, I've been encountering an issue where the 'isLoading' state is returning undefined when using useMutation. Here's the code snippet in question: const useAddUserNote = (owner: string) ...

Angular2: Ensuring Sequential Execution Line by Line - A Comprehensive Guide

I have a designed an Angular2 Navbar Component that features a logout button: import { Component, OnInit } from '@angular/core'; import { LoginService } from '../login.service'; import { Router } from '@angular/router'; @Co ...

Guide to exporting everything within a div as a PDF using Angular 2

When attempting to convert a div with the id "div1" into a PDF using JSPdf in Angular 2, everything seems to be working fine until I try to export it to PDF. Here is my code snippet: <div class="container" id="div1"> <table> <tr> & ...

The module cannot be located: Unable to find '../typings' in '/vercel/path0/pages'

Having trouble deploying my Next.js website through Vercel. It seems to be stuck at this stage. Can someone assist me, please? I've attempted deleting the node_modules folder and package-lock.json, then running npm install again, but unfortunately it ...

What could be causing a custom Angular library to fail to compile after being published on npm?

I recently launched a library that I created for my team to expedite the process of developing applications specifically for the Internet of Things (IOT) sector. However, I have encountered an issue where the library compiles without errors in the demo pro ...

Best practices for Rest API design: Enumerate potential values for entity attributes

Exploring the most effective method for populating dropdown lists in a UI with data and determining the optimal REST URI structure to support this process. Let's consider an entity called Car, which includes an attribute called "type". The type attr ...

Exploring Facebook Graph API response with Angular 2 Mapping

I am using HTTP calls to access the Graph API in order to retrieve posts from a Facebook page. Here is the code snippet that fetches an array of posts: let url = 'https://graph.facebook.com/15087023444/posts?fields=likes.limit(0).summary(true),comme ...

Typescript encounters Duplicate error when method overloading is implemented

Below is the code snippet that I am working with: public async insert(data: iFlower | iFlower[]): Promise<iFlower> | Promise<iFlower[]> { await this.insert(data); } private async insert(data: iFlower): Promise<iFlower>{ .... return d ...

Developing Angular components with nested routes and navigation menu

I have a unique application structure with different modules: /app /core /admin /authentication /wst The admin module is quite complex, featuring a sidebar, while the authentication module is simple with just a login screen. I want to dyn ...

TypeScript does not verify keys within array objects

I am dealing with an issue where my TypeScript does not flag errors when I break an object in an array. The column object is being used for a Knex query. type Test = { id: string; startDate: string; percentDebitCard: number, } const column = { ...

Issue with TypeScript retrieving value from an array

Within my component.ts class, I have defined an interface called Country: export interface Country{ id: String; name: String; checked: false; } const country: Country[] = [ { id: 'India', name: 'India', checked: false}, { ...

Attempting to limit the user's input to only the beginning of the string

To prevent unexpected data from affecting the database and front end display, I am looking to limit users from inputting a negative sign at the beginning of their number only. My attempted solution so far: if(e .key Code == 109) { return ; } ...

The data is not being displayed in the table

I am encountering an issue while attempting to populate the table with data received through props by looping over it. Unfortunately, the data is not rendering on the UI :( However, when I manually input data, it does show up. Below is my code: Code for P ...