Angular UI-Utilities with an added highlight filter

In my treeview structure, I have implemented a search feature. Now, I am looking to add the functionality to highlight multiple search words. I have tried using Angular's ui-utils and the highlight filter, but it only works for highlighting a single word at a time.

For example, if my string is "I am Test one" and I search for "I am", it will be highlighted. However, when I search for "I Test", the highlight feature does not work. I need the ability to highlight multiple words at once.

Has anyone else encountered this issue? Thank you in advance.

Answer №1

If you want to customize your search filtering process, consider developing a unique filter inspired by Angular UI's Highlight plugin. This custom filter can break down the search query into individual words based on spaces. Here's an example:

YOUR_CUSTOM_MODULE.filter('customHighlight', function () {
  return function (text, search) {
    if (text && (search || angular.isNumber(search))) {
      text = text.toString();
      search = search.toString();

      angular.forEach(search.split(/\s+/), function(search_part) {
        text = text.replace(new RegExp(search_part, 'gi'), '<span class="custom-highlight">$&</span>');
      });
    }
    return text;
  };
});

If desired, you have the option to modify the highlighting class from "custom-highlight" to one of your choosing.

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

Angular error TS2322 arises when attempting to assign a type of 'Observable<{}>' with the share() operator

Currently diving into Angular 5, I've been exploring the Observable/Observer pattern to facilitate event sharing and data changes among subscribers. Below is a snippet of the code in question: ... @Injectable() export class NidoService { ... eve ...

Explore relevant Pill information dynamically based on the image that was clicked in Angular

In this particular situation: Using Angular 1.7.2 Utilizing Bootstrap 3 Encountering some challenges after the user interacts with the image: Current Behavior: Upon clicking any image, a modal window appears displaying relevant content. If image 1 is ...

The checkbox click function is not functioning properly when placed within a clickable column

In my coding project, I decided to create a table with checkboxes in each column. <table class="bordered"> <thead> <tr style="cursor:pointer" id="tableheading" > <th>Name ...

The Parse.com cloudcode refuses to enter the success or error state

Running this code in my Parse cloud, I noticed that when I call it from my app, it never enters the success or error statement. Could it be because the .save method isn't working? Any assistance would be greatly appreciated :) This is how I invoke t ...

The canvas is unable to render the image from the sprite sheet

I successfully drew an image representing the player, but now I'm encountering difficulties in drawing an enemy character. Despite adding alerts indicating that the program is executing the draw enemy function, the enemy character still doesn't a ...

I'm running into some issues with flexbox and I'm in need of some assistance to find

I positioned two divs next to one another, but instead of each taking up 100vw, they are both sharing 50% of the available space. Is there a solution for this issue? Thank you. Page Image import type { AppProps } from "next/app"; import "./global.cs ...

Transferring Data from Controller to HTML in AngularJS Version 1

Recently, I started working with angularjs on a new project that involves three main HTML files. The first file is index.html, which contains the ng-view directive. The second file is home.html, where various products are displayed from a database. Each pr ...

Creating a 3D object using three.js framework

When playing video games, I often notice a common pattern where hovering the mouse over an object triggers a gradient highlight around its 2D representation. To recreate this effect in my Three.js scene, I started by setting up the necessary raycaster vari ...

Customizing URLs in AngularJS using ui-router allows for more personalized

Hey there, I've encountered an issue with my app. Users can sign up as merchants and have their own store name with a URL structure like this: http://localhost:8000/#/storename The problem arises when the default homepage subpages, such as contactus ...

HTML // jQuery - temporarily mute all audio for 10 seconds after page reload

Is there a way to automatically mute all audio sounds on my website for the first 10 seconds after it is reloaded, and then unmute again? <audio id="musWrited" autoplay> <source src="sound/soundl.mp3" type="audio/mp3" /> // < ...

Discover the path with the power of JavaScript

Imagine I am including a JavaScript file in this manner: <script type="text/javascript" src="http://foo.com/script.js?id=120#foo"></script> Would it be possible to access the GET or hash parameters passed through this? Currently, I achieve t ...

Make sure to include the onBlur and sx props when passing them through the slotsProp of the MUI DatePicker

This DatePicker component is using MUI DatePicker v6. /* eslint-disable no-unused-vars */ // @ts-nocheck import * as React from 'react'; import { Controller } from 'react-hook-form'; import TextField from '@mui/material/TextField&a ...

Exploring the usage of the Date method in React

When I insert the given code snippet import React,{Component} from 'react'; import ReactDOM from 'react-dom'; import './index.css'; class Date extends React.Component{ dataToString = (d) =>{ ...

The submit button remains disabled despite completing all required fields

https://jsfiddle.net/xrxjoaqe/ I'm encountering an issue with the bootstrap inline validation files. Despite filling in all the required fields, the submit button remains disabled. $('#registerbutton').attr('disabled', 'di ...

jQuery's Multi-Category Filter feature allows users to filter content

I have been working on creating a filter function for my product list. The idea is that when one or more attributes are selected, it should fade out the elements that do not match. And then, if a filter is removed, those faded-out items should fade back in ...

Identifying mouse proximity through processing.js

I am using processing.js for coding. I am trying to dynamically adjust the size variable so that it increases as the cursor approaches the ellipse and decreases as the cursor moves away from it. I also want to set a limit for the size, preferably between 5 ...

When you hover over them, Material UI icons shrink in size due to the Border

I've been working on a React application that includes Material UI icons in the header. My goal is to add a border at the bottom of each icon when hovered over, but currently, the borders are too close to the icons. Another problem I'm facing is ...

Troubleshooting Issues with https.request and Options in NodeJS Leading to Connection Resets

When working with NodeJS, I noticed that my code performs as expected when using https.get() to retrieve responses. However, the moment I make the switch to https.request() along with requestOptions, I encounter a connection reset error along with the foll ...

Error: The term 'RequestCompleted' is not recognized by Microsoft JScript

Does anyone have any suggestions? The error above occurs when this code is executed: Sys.WebForms.PageRequestManager.getInstance().add_endRequest(RequestCompleted); Specifically within this section: <script language="javascript" type="text/javas ...

I am seeking to incorporate several Three.js animations into my HTML document, but I am experiencing issues with them

As a professional graphic designer, I am facing an issue with Three.js https://i.sstatic.net/6ZsWa.jpg I have tried several solutions, but none seem to work effectively. In my attempt, I duplicated the imported model and changed its name. Despite trying ...