Sort out the information in the table

Seeking assistance on how to filter a table based on certain conditions. Refer to the sample image provided in the link below: https://i.sstatic.net/Egvj6.png

Here is the code I have attempted:

    this.reportData.filter(it => {
        if (
            it.startTimeFilter.includes(this.startdatefilter) &&
            it.endTimeFilter.includes(this.enddatefilter) &&
            it.status.toLowerCase().includes(this.status)
        ) {
            this.filteredData.push(it);
        }
    });

Answer №1

Sure, I can provide you with some tips on how to achieve this without sharing the entire code. Just remember to never modify this.reportData as all data must be retained for filtering purposes.


 applyFiltering(){
    this.dataToShowOnUI = getFilteredData();
 }

 getFilteredData(): any[]{
    let filteredData = JSON.parse(JSON.stringify(this.reportData));
    if(this.startdatefilter && this.enddatefilter){
      filteredData = filteredData.filter(it => 
            it.startTimeFilter.includes(this.startdatefilter) &&
            it.endTimeFilter.includes(this.enddatefilter) 
      );
    }
    if(this.status){
     filteredData = filteredData.filter(data => data.status.toLowerCase().includes(this.status))
    }
    if(this.operatingSystem){
        filteredData = filteredData.filter(data => data.operatingSystem.toLowerCase().includes(this.operatingSystem))
    }
    // and so on ...
    return filteredData;
 }

Answer №2

If we assume that the variables this.reportData and this.filteredData are arrays, then using the filter method correctly would look like this:

this.filteredData = this.reportData.filter(item => 
    item.startTimeFilter.includes(this.startdatefilter) &&
    item.endTimeFilter.includes(this.enddatefilter) &&
    item.status.toLowerCase().includes(this.status)
);

In essence, the filter parameter should be a function that returns a boolean value (indicating whether the element should be retained), resulting in a new filtered array without altering the original one.

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

Using jQuery to extract the value of 'selectedValue' from RadDropDownList

My goal is clearly stated in the title. Within my '#dropdown' control, the value currently looks like this: value="{"enabled":true,"logEntries":[],"selectedIndex":8,"selectedText":"Option2","selectedValue":"250"}" I am specifically interested ...

What are some strategies for safeguarding a disabled button?

Is there a way to securely disable a button if the user does not have permission to access it? I currently disable it at the Page_Load event: Page_Load() { if(!userhasrights) { btn.Enabled=false; } } However, after rendering, ASP.N ...

Error: Angular7 Unable to locate namespace 'google'

I am currently utilizing the import { MapsAPILoader } from '@agm/core'; package to enable auto-complete address search functionality. However, I have encountered an error message stating cannot find namespace 'google'. The error occu ...

Angular router link circles back to its originator

I've been working on a basic login page that transitions to a homepage once the user successfully logs in. So far, I've focused solely on the HTML structure of the login component without implementing any code in the corresponding TypeScript file ...

What is the significance of having nodejs installed in order to run typescript?

What is the reason behind needing Node.js installed before installing TypeScript if we transpile typescript into JavaScript using tsc and run our code in the browser, not locally? ...

Exploring the process of writing JSON in Angular to retrieve diverse data points

I have successfully printed the following JSON data in Angular from a local file: [{ "Firstname": "Steve", "Lastname": "Jansson" }, { "Firstname": " ...

Please ensure all three of the last checkboxes are ticked before finalizing submission

Here is the list of checkboxes for my PHP form. I am trying to figure out how to write a script that will only allow the form to be submitted if the last three checkboxes are checked. I have tried looking at similar questions but haven't found the sol ...

Adding a geometry to three.js and dynamically rotating it in real-time

Check out https://jsfiddle.net/pmankar/svt0nhuv/ for more info. The primary large red icosahedron geometry continues rotating along the y-axis. I successfully incorporated a small red sphere geometry and merged it with the primary geometry. Everything was ...

Having trouble rendering Next.JS dynamic pages using router.push()? Find out how to fix routing issues in your

The issue I am facing revolves around the visibility of the navbar component when using route.push(). It appears that the navbar is not showing up on the page, while the rest of the content including the footer is displayed. My goal is to navigate to a dy ...

transferring JSON information to a template in a NodeJs application

Currently, I am performing some filtering on my JSON data and storing the result in a variable called driver. The driver variable contains JSON data that I want to pass unchanged to the view. My main query is: How can I effectively send the data stored i ...

Every time I try to loop through my JSON object using an $.each statement, an error is thrown

When I execute an $.each loop on my json object, I encounter an error 'Uncaught TypeError: Cannot read property 'length' of undefined'. It seems that the issue lies within the $.each loop as commenting it out results in the console.log ...

Tips for preventing FormLabel components from turning blue when a radio button is selected

Currently, I am working on a Reactjs project that utilizes Material Ui components. In this project, I am tasked with creating a form to generate a new event where users can select the event location type from three options - In-Person, Hybrid, and Virtual ...

The proper way to incorporate HTML within JSON in Django Templates for safe usage

What is the best way to securely display JSON data in a Django web application? In my Django server, I create JSON data and then display it in a Django template. Sometimes, this JSON data contains snippets of HTML. While this usually works fine, if the &l ...

What is the best way to download the entire page source, rather than just a portion of it

I am currently facing an issue while scraping dynamic data from a website. The PageSource I obtain using the get() method seems to be incomplete, unlike when viewing directly from Chrome or Firefox browsers. I am seeking a solution that will allow me to fu ...

Unable to connect my Angular library with another Angular library

Issue with Angular Libraries Within my project, I have created several angular libraries stored in different folders: /home/user/lib1 /home/user/lib2 /home/user/lib3 The lib2 and lib3 libraries are dependent on the lib1 library. // Example of the lib3.m ...

HTTP-Proxy load balancing techniques

Currently exploring the http-proxy module. From what I gathered, it balances between two different hosts with the same port. My question is, can it also balance between two different ports while using the same hosts (for example, both hosts having the sa ...

Please ensure that the table contains all the records corresponding to the respective days

I am struggling with figuring out how to display a record of classes in my table view. The UX prototype I need to follow is shown https://i.stack.imgur.com/CISYn.png (the days of the week are in Portuguese: horario = time, segunda = Monday, terça = Tuesda ...

Encrypting data using SSL in javascript and python simulation

Due to the restrictions imposed by the Great Firewall of China, Google AppEngine's secure https port has been blocked. To ensure the protection of my users' information from being intercepted by ISPs and the GFW, I am planning to create a Secure ...

The HTML5 range input is consistently defaulting to the minimum value and is not triggering the onChange event for text input

My goal is to implement a feature where an input type text is used along with an input type range with three specific use cases: 1. Default case: When the page loads, the slider should point to the value specified in the text input field. 2. When a user e ...

Is there a way to reach my vue instance while inside a v-for iteration?

When using a v-for loop, I encounter an error: <div v-for="index in 6" :key="index"> <div class="card h-100" style="margin-top: 200px;"> <a href="#"> <img ...