Activate filtering beyond the AngularJS datatable

Currently, I am experimenting with a codepen to understand how to filter data based on a clicked span element. The table is where the data is displayed and I'm looking for a way to trigger filtering outside of it. While the angularjs documentation specifies using filters with ng-repeat, I am unsure about implementing the filtration process when a specific span element is clicked. Can anyone guide me on how to proceed? I have an openModal function that works when a button is clicked but doesn't affect the display of the data. Thank you for any assistance.

HTML

<div class="container" ng-app="myApp" ng-controller="myController">
  <div class="row">
    <div class="col-12">
      <div class="row">
        <div class="col-6 my-auto">
          <span>All</span>
          <span>Hawks</span>
          <span>Sparrows</span>
          <span>Doves</span>
        </div>
        <div class="col-6 my-auto">
          <label class="my-auto float-right">Search:
            <input ng-model="searchText">
          </label>
        </div>
      </div>
      <div class="row table-responsive">
        <table id="searchTextResults" class="table table-striped">
            <tr>
                <th ng-click="sortBy('ID')">ID</th>
                <th ng-click="sortBy('Name')">Bird Name</th>
                <th ng-click="sortBy('Type')">Type of Bird</th>
            </tr>
          <tr>
                        <tr ng-repeat="birds in list | filter:searchText | orderBy:sortField:reverseOrder">
              <td><a href="#">{{birds.ID}}</a></td>
              <td><a href="#">{{birds.Name}}</a></td>
              <td><a href="#">{{birds.Type}}</a></td>
<td><button ng-click="openModal()" class="myBtn">Edit</button></td>
            </tr>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>

Answer №1

To incorporate a ng-click function into the span element, simply add it and set the searchText variable when clicked. Refer to the demonstration provided below. To streamline this process even further, you can dynamically generate span elements using ng-repeat instead of hard coding them. This way, any new span element can be easily added to the array. Hopefully, this explanation is helpful.

A more simplified version would resemble the following:

<span ng-repeat="tab in tabs" ng-click="update(tab.value)">{{tab.label}}</span>

 $scope.tabs = [ { value: '', label: 'All' }, { value: 'Dove', label: 'Doves'}]; 

 $scope.update = function(filterText) {
      $scope.searchText = filterText;
 }
...

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

Mastering the art of switching between different application statuses in ReactJS

As a newcomer to reactJS, I am exploring ways to make one of my components cycle through various CRUD states (creating object, listing objects, updating objects, deleting objects). Each state will correspond to displaying the appropriate form... I have co ...

Having trouble with Angular2's Maximum Call Stack Exceeded error when trying to display images?

I am facing an issue in my Angular2 application where I am trying to display an image in Uint8Array format. The problem arises when the image size exceeds ~300Kb, resulting in a 'Maximum Call Stack Exceeded' error. Currently, I have been able to ...

Accessing Protected API Endpoint Fails Following Successful Login in Node.js Express API

After developing registration and login APIs with Express, Mongoose, and Node.js, I am currently testing them using Postman. The registration and login functionalities are functioning properly, as the tokens are successfully stored in both cookies and head ...

Updating the source content of an iframe in real time

Currently, I am working on a search result page. The scenario involves a login page redirecting to a homepage that consists of a dropdown menu, a textbox, a button, and an iframe displaying a table with user data (firstname, lastname, middlename). Upon sel ...

Using ExtJS to populate a panel with data from various sources

I am currently working with an Ext.grid.GridPanel that is connected to a Ext.data.JsonStore for data and Ext.grid.ColumnModel for grid specifications. Out of the 10 columns in my grid, 9 are being populated by the json store without any issues. However, I ...

Display a partial form in Rails using Ajax

There is a form displayed in the image below: Next, I aim to render this partial from an ajax call, specifically from .js.erb. However, I am unsure how to pass an object to f from the partial. Take a look at the image below for reference: Is there a way ...

How to retrieve the href attribute within an anchor tag using jQuery with a selector based on the div/span ID and the

Hello, I'm new to jQuery and I was hoping someone could help me with extracting the href attribute from an anchor tag using a div or span ID selector along with the anchor tag's class. <span id="view-post-btn"><a href="https://blog.comp ...

Sending Data from Dialog Box1 to Dialog Box2 in ASP.NET Using JavaScript

Is there a way to successfully transfer a value from Modal1 to Modal2? I am facing an issue where Modal1 opens Modal2 to receive a necessary value, but I keep encountering the error message: "Uncaught TypeError: Cannot read property 'click' of nu ...

What are the steps for launching a Yeoman Angular-Fullstack project?

I'm looking to launch a basic Angular project created with the angular fullstack framework. https://github.com/DaftMonk/generator-angular-fullstack I've attempted: yo angular-fullstack test grunt build After this, I ended up with 2 folders i ...

Guide on transferring information from .ejs file to .js file?

When sending data to a .ejs file using the res.render() method, how can we pass the same data to a .js file if that .ejs file includes a .js file in a script tag? // Server file snippet app.get('/student/data_structures/mock_test_1', (req, res) = ...

Looking for a .NET MVC AJAX search solution. How can I enhance the code below?

I am looking to implement a search functionality using AJAX. I have tried using the get method in my controller by passing the search string, but it is not working as expected. Below is a snippet of my controller code, where I retrieve the search value fr ...

The ID value did not pick up the number 0 when passed to the next blade after the initial reading

When passing an ID value to another blade file, I encountered an issue where the other blade file did not read the number 0 at the beginning. For example, if I pass the value of 006, when I console log the value in the other blade view, it only shows 6. H ...

Having difficulty deleting an entry from a flatList in a React Native component when using the filter method

I'm currently facing an issue with deleting an item from my flatlist in React Native. I've been attempting to use the filter method to exclude the list item with the ID entered by the user for deletion, but it's not working as expected. I&ap ...

Sending data from jQuery to an AngularJS function is a common task that can be accomplished in

In my Controller, I have a function that saves the ID of an SVG path into an array when a specific part of the image.svg is clicked. $(document).ready(function(){ var arrayCuerpo=[]; $('.SaveBody').on("click", function() { ...

Node.js is known for its unreliable promise returns

Currently, I have a function in place that establishes a connection with a sql database. After querying the database and formatting the results into an HTML table, the function returns the variable html: function getData() { return new Promise((resolv ...

Creating several Doughnut Charts within a single Canvas using Chart.js

Is there a way to display multiple layers of a doughnut chart simultaneously using Chart.js? Currently, I'm only able to see one layer at a time and the others become visible upon hovering over their position... If you have any insights on how to mak ...

Problem with YouTube iFrame API in IE when using JavaScript

Apologies for the unclear heading, but I'm facing a peculiar issue. The YouTube iFrame API works perfectly on all browsers except Internet Explorer. In IE, none of the JavaScript code runs initially. However, when I open DevTools and refresh the page, ...

Struggling with a TypeORM issue while attempting to generate a migration via the Command Line

Having some trouble using the TypeORM CLI to generate a migration. I followed the instructions, but when I run yarn run typeorm migration:generate, an error pops up: $ typeorm-ts-node-commonjs migration:generate /usr/bin/env: ‘node --require ts-node/regi ...

Distinguishing between a save and update using a shared Angular JS template

Currently, I am engaged in a project that involves a PHP backend and Angular 1.x on the front end. Within this project, there is a Listings model used in conjunction with a common template for both adding and editing Listings. The challenge lies in distin ...

Creating a bucket in Autodesk Forge Viewer is a straightforward process with the Forge API

I am currently facing an issue while trying to create and upload a new bucket for storing models. I keep getting a 400 Bad Request error, even though I managed to make it work in a previous project using a different method. Strangely enough, I now encounte ...