Locate and refine the pipeline for converting all elements of an array into JSON format using Angular 2

I am currently working on implementing a search functionality using a custom pipe in Angular. The goal is to be able to search through all strings or columns in a received JSON or array of objects and update the table accordingly.

Here is the code snippet of my Custom Pipe (although it's not performing as expected):

transform(items: any[], args:string): any {
    let keys = [];
    for (let key in items) {
            keys.push({key: key, value: items[key]});
    }
    let ans = [];
    for (let k in keys){
        if(items[k].value.match('^.*' + args +'.*$')){
            ans.push({key: k, value: items[k]});
        }
    }
    return ans;  
}   

The search input HTML element :

<input type="text" #filterInput (keyup)="0">

Loading the table data using the custom pipe:

<tbody *ngIf="usersBool">
<tr *ngFor="let entry of content | filterArrayOfObjects: filterInput" >
    <td>{{entry.value.enrollmentId}}</td>
    <td>{{entry.value.firstName}}</td>
    <td>{{entry.value.LastName}}</td>
    <td>{{entry.value.typeOfUser}}</td>
    <td>edit</td>
    <td>delete</td>

</tr>
</tbody>

Dummy content example:

this.content = [
               {
                   "enrollmentId": "A0xxxxxx",
                   "firstName": "Bob",
                   "LastName": "Bob",
                   "typeOfUser": 'Admin'
               },
               {
                   "enrollmentId": "A0xxxxxx",
                   "firstName": "Bob",
                   "LastName": "Bob",
                   "typeOfUser": 'Admin'
               },
               {
                   "enrollmentId": "A0xxxxxx",
                   "firstName": "Bob",
                   "LastName": "Bob",
                   "typeOfUser": 'Admin'
               }
           ];

Answer №1

In order to find a match in my content Dictionary with the input in the search bar, I needed to carefully examine each key in the dictionary

transform(items: any[], args:string): any {

    let ans = [];
    for (let k in items){
        if(items[k].enrollmentId.match('^.*' + args +'.*$')
           || items[k].firstName.match('^.*' + args +'.*$')
           || items[k].lastName.match('^.*' + args +'.*$')
           || items[k].typeOfUser.match('^.*' + args +'.*$')) {
            ans.push({key: k, value: items[k]});
        }
    }
    return ans;

}

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

Tips for translating an HTML webpage from Arabic to English

I have a bootstrap site with HTML pages but no backend functionality. How can I manually translate from Arabic to English, given that I already have the translations for all content and don't need to rely on translation tools? Is there a way to map Ar ...

The relationship between Vue TypeScript props is influenced by the presence of another prop

Is there a way to define a property in <script setup lang="ts"> that depends on another property? For instance, how can I require a variable only if another variable is present? I attempted using defineProps<Props | PropsA>(), but e ...

Utilizing ConfigurationBuilder to incorporate null values into a list using a json file

As I attempt to insert a list of enums into appsettings.json for later iteration in the code, I encounter an issue. When I include a null value in the list within the JSON file, it does not populate as a null value when loading the Settings from the file. ...

Exploring the Possibilities with AngularJS Location Filtering

My single-page application (SPA) includes select lists used for filtering locations based on region, state/province/EU country, and city. Although I have managed to set up filtering to some extent, there are issues with the lat/lng values of the locations ...

checkbox with an option tag

I need help with implementing multi-select checkboxes inside an Angular 4 application. The checkboxes are not appearing next to the team names as intended. Can anyone assist me with this issue? Below is a snippet of my HTML code: <select class="form-c ...

Is there a way to eliminate duplicate elements from 2 arrays in Angular?

Imagine I have a scenario with two arrays: arr1 = ["Tom","Harry","Patrick"] arr2 = ["Miguel","Harry","Patrick","Felipe","Mario","Tom"] Is it possible to eliminate the duplicate elements in these arrays? The desired output would be: arr2 = ["Miguel"," ...

The properties '{ label: string; value: string; }' are required in type 'readonly never[]' for react-select, but they are missing

state = { groupPermissionValue: {label: '', value: ''}, } <Select instanceId="user-group" onChange={this.selectUserGroupOption} value={this.state.groupPermissionValue} options={this.state.groupPermission} i ...

What is the best way to transform the date time format received from the server so that it can be used with the time-ago

Issue Explanation: My server is providing the date and time in a specific format as shown below - myDate2= '22-DEC-2017 03:22:11'; The current format does not work with time-ago-pipe and results in NaN Accepted Format: myDate: String = new Dat ...

Performing an HTTP GET request in NodeJS to a specific URL in order to receive

Currently, I am attempting to execute a server-side API call using a RESTful protocol that delivers a JSON response. To better understand this process, I have extensively studied the API documentation as well as explored information provided in this partic ...

React-bootstrap-table Axios delete operation causing [object%20Object] to be displayed in the browser console

I am having trouble executing a delete operation using axios on a react-bootstrap-table, and encountering this error in the console DELETE http://localhost:9000/api/terminals/[object%20Object] Uncaught (in promise) Error: Request failed with status cod ...

What is the best way to hide the next/previous tabs once the jQuery dataTable has been set up using jSON data

Setting up a jQuery table using JSON data. Despite knowing that there will only be one row, the next/previous tabs are still displayed after the table. Is there a way to remove them? Here is the code for the table: table = $("#retrievedTable").dataTabl ...

You are unable to elongate the interface 'http.IncomingMessage'. Were you intending to use 'implements' instead?

I have been struggling to execute the serve command for my angular project, encountering errors every time. Despite searching on Google for solutions, I have now reached a point where none of the answers seems to be helping. I recently downloaded a MEAN st ...

What is the process of integrating Formik with Chakra using typescript?

I'm attempting to implement the following Chakra example in Typescript. <Formik initialValues={{ name: "Sasuke" }} onSubmit={(values, actions) => { setTimeout(() => { alert(JSON.stringify(values, null, 2)); actio ...

Issue with Google Charts - Chart is unable to render because data table has not been defined

Using Ajax, I attempted to set an Interval for my Google Chart, but unfortunately, the Chart is not being drawn. Instead, I repeatedly receive the error message: "Data table is not defined." every 5 seconds. If you want to see a screenshot of the error mes ...

The absence of certain attributes in TypeScript

class DeploymentManager { import { observable, action, makeAutoObservable } from "mobx" public deploymentQueue = observable<IDeploymentProject>([]); public inProgressProjects = observable<IDeploymentProject>[]; public s ...

What is the process for setting the version in a serverless project?

Recently I downgraded the serverless to version 1.38.0 using the command npm install -g <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="047761767261766861777744352a373c2a34">[email protected]</a>. This triggered in ...

How can I emphasize the React Material UI TextField "Cell" within a React Material UI Table?

Currently, I am working on a project using React Material UI along with TypeScript. In one part of the application, there is a Material UI Table that includes a column of Material TextFields in each row. The goal is to highlight the entire table cell when ...

Tips for managing the dimensions of the <label> element within a React component

I'm facing an issue where the element size is not matching the box size as expected. Additionally, the width property doesn't seem to work in React. Does anyone know how to solve this problem? const DragDrop = () => { ... return ( &l ...

Unexpected token error occurs when making cross-domain AJAX requests to the server and receiving a JSON object

I have set up an express server to handle get requests to specific url endpoints. When responding to these requests, I am sending back data in JSON format to enable making Ajax calls and retrieving data from the page. To allow for cross-domain requests, I ...

Ways to inform websocket client of authentication failure

Utilizing the (ws package) in Node.js to handle websockets, I leverage the "on upgrade" event to authenticate incoming clients based on a token provided as a URL parameter. Following the guide here, if the token is invalid/missing/expired, I utilize the fo ...