Display data in an HTML table based on user search input using Angular

I am currently working on integrating a JSON file into my project, which will eventually be accessed through an API from a server. Right now, I am pulling data directly from an object.

My goal is to build an HTML file that features a table with navigation tabs for each header element. Each tab should also include a search box and a submit button.

The initial state of the table should be empty. When a user searches for a specific value (such as ID, nickname, email, etc) within one of the headers, the table should populate with the JSON data that matches or contains part of the search query.

As a newcomer to Angular syntax, I am struggling to conceptualize how this functionality should be implemented within the framework.

(function() {

    var app = angular.module('tool', []);

    app.controller('searchController', function() {
      this.info = data.people;

      this.findId = function(idInput) {
        angular.forEach(that.id, function(value, key) {
          if (value.contains(idInput)) {
            // Unsure about what code needs to go here.
          }
        });
      };

    });

    var data = {
      "people": [{
          "id": "2245231",
          "nickname": "heyyman",
          "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8be2e5ede4cbece6eae2e7a5e5eeff">[email protected]</a>",
          "lastIp": "127.0.0.1",
          "regIp": "127.0.0.1",
        }, {
          "id": "2245232",
          "nickname": "heyyman2",
          "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9b0b7bfb6eb99beb4b8b0b5f7b7bcad">[email protected]</a>",
          "lastIp": "127.0.0.2",
          "regIp": "127.0.0.2",
        }
      };

    })();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<main>
  <table ng-controller="searchController as search">
    <thead>
      <tr id="tableNavigation">
        <td></td>
        <td>ID
          <input type="text" ng-model="idInput">
          <input type="submit" ng-click="findId(idInput)">
        </td>
        <td>Nickname</td>
        <td>Login / Email</td>
        <td>Last IP</td>
        <td>Registration IP</td>
      </tr>
    </thead>
    <tbody id="tableCanvas">
      <tr ng-repeat="people in search.info" ng-class-even="'even'">
        <td></td>
        <td>{{people.id}}</td>
        <td>{{people.nickname}}</td>
        <td>{{people.email}}</td>
        <td>{{people.lastIp}}</td>
        <td>{{people.regIp}}</td>
      </tr>
    </tbody>
  </table>
</main>

This is the progress I have made so far, along with a link to the JSFiddle sandbox where you can see the implementation.

http://jsfiddle.net/ho00cLkk/

If you find any confusion or lack of clarity in my explanation, please let me know.

Answer №1

Upon reviewing your inquiry, it appears to contain two distinct sections:

  1. How can I apply filters to the displayed items?
  2. Is there a way to conceal all outcomes until the initial search is conducted?

Given that the second question does not pique my interest (due to numerous potential solutions and lack of a universal issue), I will focus on addressing the first query. I recommend referring to the official documentation available at: https://docs.angularjs.org/api/ng/filter/filter. By following the guidelines outlined in the documentation, achieving this task is straightforward and does not necessitate the use of submit buttons.

<table>
    <thead>
        <tr>
            <th>
                Name
                <input type="text" ng-model="searchProps.name">
            </th>
            ...
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in people | filter:searchProps">
            ...
        </tr>
    </tbody>
</table>

(in this scenario, ensure that people corresponds to your search.info). The table rows will automatically undergo filtration processes, displaying only those items with properties that partially match the values identified within searchProps.

An illustrative CodePen demonstration can be accessed here: http://codepen.io/anon/pen/jEEZaa

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

Locate the final element within an array using JavaScript

Provided with a file path like new/lib/java.exe, I am looking to eliminate the root folder 'new' and structure the new path as lib/java.exe. Challenge: After my attempts, I am left with the path as lib/java.exe/ which includes an unwanted "/". I ...

Troubleshooting problem with Z-Index conflict in Flash animation

I am facing an issue with two HTML divs - one containing a flash movie and the other simple text. I want to place the textual div on top of the flash movie div, but no matter how I set their positions in CSS or adjust their Z-Index values, the text keeps ...

Retrieve information from json, divide it, and transfer it to the chart for display

Greetings everyone! In my project, I am parsing a JSON file from an online API. However, I have encountered a roadblock while trying to split the data. Despite searching extensively on platforms like YouTube, I haven't been able to find a solution tha ...

Creating a realistic typewriter effect by incorporating Code Block as the input

I am looking to add a special touch to my website by showcasing a code segment with the Typewriter effect. I want this code block not only displayed but also "typed" out when the page loads. Unfortunately, I have been unable to find a suitable solution s ...

unable to retrieve the value of this.table property within a JavaScript class

In my JavaScript code, I have created a class that generates a MySQL model like so: class Model { constructor(options = {}, table) { this.options = options; this.table = table; this.create(); } create() { let queryString = `INSERT INT ...

How can I redirect after the back button is pressed?

I am currently working with a trio of apps and scripts. The first app allows the user to choose a value, which is then passed on to the second script. This script fetches data from a database and generates XML, which is subsequently posted to an Eclipse/J ...

Utilize Nuxt.js context within a Vue plugin

I have a situation where I'm working with Nuxt.js and have two plugins set up. In order to gain access to the VueI18n instance from lang.js within validate.js, I am in need of some guidance. Is there anyone familiar with how this can be accomplished? ...

NodeJS Integration Issue with AngularJS Implementation

I am a beginner in the world of MEAN Stack development. Recently, I tried creating a simple HTML page with some AngularJS code that works perfectly when opened directly in my browser. However, when I attempt to render it using my Node.js server, the Angula ...

Using Typescript/JSX to assign a class instance by reference

Looking to access an object's property by reference? See the code snippet below; class Point{ x:number; y:number; constructor(x,y) { this.x=x; this.y=y; } } const a = { first: new Point(8,9), second: new Point(10,12) }; let someBoo ...

You cannot nest a map function within another map function in React

Having some trouble applying the map function in HTML using React. Below is the code snippet: response = [ data : { name: 'john', title: 'john doe', images: { slider: { desktop: 'link1', mo ...

The aggregation pipeline in nodeJS with mongoDB is failing to return any results, returning an empty array instead

Currently, I am enrolled in Jonas Schmeddtman's Node.js course where I am working on developing a tour App. However, I have encountered an issue where sending a request via Postman on the specified route results in an empty array instead of the expect ...

Electron.js issue: ipcRenderer and ipcMain leading to a white screen problem

I am currently working on a desktop application using Electron, Vue, and Vuetify. However, I have encountered an issue where sending data from the rendererProcess to mainProcess using IPC results in a white blank screen. I'm unsure of what is causing ...

Angular fails to refresh the display

For a while now, I have been working with Angular without encountering many difficulties. I have a controller that triggers a function on an ng-change event. This particular controller is responsible for generating different reports based on select filters ...

When incorporating "<" or ">" into a parameter value in Angular Translate and then showcasing it in a textarea with ng-model

In my Angular Translate string, I am using a parameter that can be in the form of <test>. However, when this translate is displayed in a textarea, it shows up as &lt;test&gt; instead of <test>. Is there a way to ensure it appears correc ...

Switching from a click event to a hover event in JavaScript

I've been experimenting with animating a burger bar on hover and came across an example online that I managed to adapt for mouseenter functionality. However, I'm struggling to make it revert back to the burger bar shape once the mouse leaves on m ...

Dynamic popup in RShiny interface with the ability to be moved around

I am currently working on a dashboard project and I am looking to implement a dynamic popup feature that can be moved around. I have been able to create a pop-up, but it remains static. I would like the flexibility for users to drag and position the popup ...

Determine whether a click event originated from within a child window

Currently, I am utilizing window.open to initiate a new window in javascript and my goal is to identify clicks made within the child window. Essentially, if a click event occurs in the child window, I aim to modify the parent window accordingly. I have a ...

What is the reason behind Angular not allowing users to define @Output events that begin with 'on'?

While developing a component, I defined an output EventEmitter named onUploaded. However, Angular flagged an error instructing me to use (uploaded) instead. This restriction is due to security concerns, as bindings starting with 'ono' pose risks. ...

Utilizing AJAX to Load JSON File Compressed with GZIP

I utilized the gzip algorithm to compress a JSON file, following this method (source: java gzip can't keep original file's extension name) private static boolean compress(String inputFileName, String targetFileName){ boolean compressResu ...

What is the best way to use jQuery to select a group of table rows based on the value of a

My current issue involves using a jQuery selector to move table rows "UP" and "Down." Here is the Table structure in HTML: jQuery Portion : $(".up,.down").click(function() { var row = $(this).parents("tr:first"); if ($(this).is(".up")) { ...