Angular: Enhancing table functionality by implementing a search bar and customized filters for content refinement

Currently, I am working on a project involving a datatable with various filtering options:

https://i.sstatic.net/uFFWP.gif

The HTML code snippet is as follows:

<div class="row topbuffer-20">
  <div class="col">
    <h3>Thief: The Dark Project</h3>
    <p>There are <span *ngIf="fanmissions"><strong>{{fanmissions.length}}</strong></span> available Fan Missions. The last released is <strong>Veniam in Sunt Pariatur</strong> and the last updated is <strong>Ullamco Ad in Elit</strong>.</p>
  </div>
</div>
...

To-do list:

  1. Filter items by entering a value in the search input. This filter should be able to filter by ID, Name, Author, Game abbreviation, Game full name, Version, First release date, and Last update date.
  2. Filter items by clicking one of the three filter options. When an option is selected, only the relevant items should be visible. Only one option can be active at a time.
  3. Update the main heading based on the active filter option. The heading should display the full name of the game for the active filter option.
  4. Update the paragraph below the main heading based on the filter options. It should reflect the total number of items in the database, the latest published item, and the most recently updated item when no filters are applied. When using the search input, it should display the number of available items and details of the latest updates.
  5. Enable sorting of the datatable content ASC/DESC based on table head clicks.
  6. Show "No result found" if there are no search results.

I require custom Pipes to implement these functionalities in my ectm-list.component.

Please check out my GitHub project structure for reference:

Seeking assistance to accomplish this task successfully!


1. Filter items writing a value in the search input

Currently, I can only filter by NAME using the following Pipe:

@Pipe({
  name: 'EctmFilterFMsBySearch'
})
export class EctmFilterFMsBySearchPipe implements PipeTransform {

  transform(value: any, arg: any): any {
    if (value != null && arg != null) {
      var filteredfanmissions = value.filter((fanmission) => fanmission.name.search(new RegExp(arg, "i")) >= 0);
      if (filteredfanmissions != 0) {
        return filteredfanmissions;
      }
    } else {
      return value;
    }
  }

}

Need to modify fanmission.name to include other listed filter options mentioned earlier. How can this be achieved? Is a loop necessary?

Answer №1

When working on an application, I encountered a similar situation where I had to deal with filtering data. Instead of using filter as a pipe, I found it more effective to use it as a service. By passing in the column name and input text as variables to the function, you can easily return the desired results. For example, you can utilize fanmission."column name i.e name/id".search(new RegExp(arg, "i")) >= 0)

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 numerical value of zero in React Native TypeScript is being interpreted as NaN

When attempting to map an array in React Native (Android) and use its values or keys as data for return, I encountered an issue where the value 0 is read as NaN. This problem also arose when utilizing a typescript enum. The versions I am using are: typesc ...

We regret to inform you that an unexpected runtime error has occurred: TypeError - require.e is

Upon initially loading my page in development mode, I encounter the following error: Unhandled Runtime Error TypeError: require.e is not a function 8 | import {VideoType} from "../../component/VideoPlayer/Types"; 9 | > 10 | const Loc ...

Uncover the solution to eliminating webpack warnings associated with incorporating the winston logger by utilizing the ContextReplacementPlugin

When running webpack on a project that includes the winston package, several warnings are generated. This is because webpack automatically includes non-javascript files due to a lazy-loading mechanism in a dependency called logform. The issue arises when ...

What causes the occurrence of `possibly null` errors within the if-condition?

We've implemented the strictNullInputTypes setting in our tsconfig.json. Within the component, there's a straightforward observable: export class ExampleComponent { obs$ = of({ prop: 12 }).pipe(delay(1000)); } In the component templa ...

Using `await` inside an if block does not change the type of this expression

Within my code, I have an array containing different user names. My goal is to loop through each name, verify if the user exists in the database, and then create the user if necessary. However, my linter keeps flagging a message stating 'await' h ...

Troubleshooting: Issue with event subscriptions in Angular 2

I am trying to trigger an Angular 2 event, but the function that should run upon subscription is not being executed. In one of my files, I have the following code for subscribing to the event: listenToLoginEvents() { this.events.subscribe('user:log ...

Utilize the up and down arrow keys to scroll through a description list in React

If you want to navigate through the list of Description Details using the tab and shift tab keys, it can be done easily. The default behavior allows for smooth navigation. <dl> <dt style={{ textAlign: "center" }}>Beast of Bodmin< ...

What is the best way to access data in a node.js application from IONIC typescript via a REST API?

Here is the structure of my service.ts: import { Injectable } from '@angular/core'; import {Http, Headers} from '@angular/http'; import 'rxjs/add/operator/map'; /* Generated class for the PeopleSearch provider. See http ...

What is the method for importing the "numeric" library version "^1.2.6" into an Angular project?

I recently added the package "numeric": "^1.2.6" to my project. In addition, I included the types: "@types/numeric": "^1.2.1" When attempting to import this into my Angular application: import * as numeric from &ap ...

Issues arising post transitioning to 14.0.0 from 13.0.0 version of ngx-masonry library leading to failed tests

Following the update to the latest stable version of the library ngx-masonry 14.0.0, our tests started failing. The release was just yesterday (24.10.2022) and you can find the changelog here: https://github.com/wynfred/ngx-masonry/blob/master/CHANGELOG.md ...

Utilizing React with Typescript to create JSX text translation files

My task involves translating text stored in a file... ///translations.txt const TEXT: { [x: string]: { [y: string]: string } } = { en: { joinNow: <React.Fragment>Join <b>Now<b/></React.Fragment>, signUp: <React.Fragmen ...

"Error encountered: Unable to resolve dependency tree" message appears when attempting to run npm install

Encountering dependency errors while trying to execute the npm install command for my Angular application. As a newcomer to TypeScript and Angular, I'm unsure of the next steps to take. Any suggestions? Attempted solutions include clearing the npm ca ...

How to add color to an HTML table depending on 3 different conditions

I have set 3 specific colors in my CSS. I have an HTML table and I am looking to have the background color of a cell change based on 3 conditions: if the cell contains the text 'True' - color green if the cell contains the text 'False& ...

Deciding when to utilize an interface, when to avoid it, and when to opt for a constructor in Typescript for the creation of JavaScript arrays

Exploring the concept of JavaScript object arrays in TypeScript In my current project, I am retrieving a JSON array from an observable. It seems that I can define and initialize the array without necessarily specifying an interface or type. let cityList[ ...

Angular Application cannot locate the interface file

Attempting to create a basic test environment for the OMBD Api. Utilizing an interface file named ombdresponse.ts: interface IOMBDResponse { Title: string; Year: string; Director: string; Poster: string; } The issue arises within the ombd- ...

What is the best method for retrieving the current value of an RxJS Subject or Observable?

I am dealing with an Angular 2 service: import {Storage} from './storage'; import {Injectable} from 'angular2/core'; import {Subject} from 'rxjs/Subject'; @Injectable() export class SessionStorage extends Storage { priv ...

How can we ensure that blanks are placed at the bottom when the primary order is based on a Case statement in SQL

I need to sort the listing items where blanks appear at the bottom of the result, but the main order by is a case statement. The main Order By clause I am using is: ORDER BY CASE WHEN pub = 1 THEN title ELSE t.othertitle END; In addition to that, I want ...

Angular2 Auth Guard causing empty page display when Observable.of(true) is used

While using auth-guard to protect certain routes, I'm encountering an issue where a blank page is displayed when attempting to retrieve a refresh token. The authenticated() method returns an Observable and the code seems to be functioning correctly wi ...

Checking the types for object literals returned from Array.map functions

Check out this demonstration I made in the TypeScript playground: interface Test{ a: string b: string } const object: Test = { a: 'b', b: 'c', } function testIt(): Test[] { const data = [{b: '2', c: &apo ...

Creating a personalized installation pathway for NPM, Angular, and TypeScript on Windows operating systems

Is there a way to prevent NPM and Angular from using the folder C:\Users\XXXXXX\AppData\Roaming\npm in Windows? I am trying to globally install Node.Js and Angular on a different disk (using the command NPM i --prefix D:\MyF ...