Interact with table cells using Angular's mousedown and mouseover events

I am looking to create a feature that highlights table cells when the mouse is pressed and hovered over a cell. Essentially, I want the cell to be highlighted whenever the mouse button is clicked and moved over it.

However, in this example, there seems to be a small glitch: every other click results in the mouse getting stuck with a disable-symbol (as shown in the screenshot), and the mousedown event does not trigger until an additional click is performed.

https://i.sstatic.net/USR6F.png

Here is the HTML snippet:

<table>
  <tr *ngFor="let rows of groups">
    <td *ngFor="let cell of rows.row" 
        (mousedown)="down(cell)" 
        (mouseover)="over(cell)"
        (mouseup)="up()"
        [class.active]="cell.isChecked"
    ></td>
  </tr>
</table>

And here is the TypeScript code:

  active: boolean = false

  down(b) {
    this.active = true
    if (this.active)
      b.isChecked = !b.isChecked
  }

  over(b) {
    if (this.active) 
      b.isChecked = !b.isChecked
  }

  up() {
    this.active = false
  }

Could this issue be related to the mouse events, the browser, or the actual code implementation?

Thank you for your assistance.

Answer №1

The symbol should have a connection to the drag-and-drop functionality. Consider including these attributes in the td element.

ondragstart="return false;" ondrop="return false;"

Answer №2

Here's an example for you to try:

.html

<table>
  <tr *ngFor="let rows of groups">
    <td *ngFor="let cell of rows.row"
        (mouseleave)="!cell.isSelected ? cell.isChecked = true : false"
        (mouseover)="cell.isChecked = false"
        (click)="cell.isSelected = !cell.isSelected"
        [class.active]="cell.isChecked"
    ></td>
  </tr>
</table>

.ts

groups = [
  {
  row: [
    { isChecked: true, src: "",isSelected :false},
    { isChecked: true, src: "",isSelected :false},
    { isChecked: true, src: "",isSelected :false},
    { isChecked: true, src: "",isSelected :false},
    { isChecked: true, src: "",isSelected :false},
    { isChecked: true, src: "",isSelected :false}
  ],
   ...
 }

Check out the demo!

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

Why is the radio button not chosen in the ns-popover popup? The radio button is only selected in the popup of the last column

In my Angular controller, I am trying to set the radio model but it is only appearing in the last column popup of the table. The ns-popover is displayed when clicking on a table column. Here is the Angular Code: var app = angular.module('app', ...

How to drop several pins on Google Maps with JavaScript

I am working on incorporating multiple markers into a Google map using ajax, javascript, and php. Although there are no errors in my code, the markers are not appearing as expected. I would greatly appreciate any assistance with this issue. Please refer to ...

What is the process for uploading a single file and an array of files with varying names using multer?

I am having trouble figuring out how to upload a main image and side images from 2 different file inputs using multer. It seems that multer only accepts one upload per route. How can I work around this issue? I keep getting an unexpected field error when a ...

Using callback functions to handle parameters in GET requests

Hey there, I'm currently diving into the world of callback functions and I have a burning question that needs clarification. Adding event listeners seems easy enough: $0.addEventListener("click", function(event){console.log(event)}); When you click s ...

Looking for a way to incorporate or locate additional files within nodejs?

I am attempting to invoke my JavaScript function from my Node.js script, however I am encountering an Uncaught ReferenceError: module is not defined issue. Within my server, I have the following: require('/public/js/script.js')(); foo(); M ...

What are the steps to incorporate an iframe containing uniquely designed XML content?

I'm currently working on a website project for a client who specifically wants to include news from the BBC. Despite spending 3 hours searching online, I haven't been able to successfully insert an XML file into an iframe and style it to the clie ...

The conversion to ObjectId was unsuccessful for the user ID

I'm looking to develop a feature where every time a user creates a new thread post, it will be linked to the User model by adding the newly created thread's ID to the threads array of the user. However, I'm running into an issue when trying ...

Utilize Vue.js to easily upload images alongside form input fields

I have recently started a small project with Vue Js. I am trying to incorporate an upload file option in my contact form. Due to the numerous input text fields, I am using serialize for the form. However, I am facing issues with the append function. How ca ...

Warning: Django is currently dysfunctional

using django 2.0.2 on mac os 10.13 with python 3.6.4 implementing alerts in templates django settings.py MESSAGE_TAGS = { messages.DEBUG: 'alert-info', messages.INFO: 'alert-info', messages.SUCCESS: 'alert-success', messages ...

How to determine if a radio button has been selected using Javascript?

I have come across scripts that address this issue, however they are only effective for a single radio button name. My case involves 5 different sets of radio buttons. I attempted to check if it is selected upon form submit. if(document.getElementById(&ap ...

Angular 2: A Glimpse into the File Contents

Currently working on a project where I need to aggregate multiple XML files with the same structure. The process involves users dropping their XML files, making some edits, and receiving an XML file with all the necessary data organized in a list of elemen ...

'The object of type '{}' does not support indexing with a 'string'

I am currently working on a React component that dynamically generates an HTML Table based on an array of objects. The columns to be displayed are specified through the property called tableColumns. While iterating through the items and trying to display ...

After defining the NEXTAUTH_URL and NEXTAUTH_SECRET variables, the getServerSession(authOptions) function in NextJS is returning null

I've been attempting to set up OAuth with the Google provider for my Next.js 13 web application. Unfortunately, I'm encountering an issue where getServerSession(authOptions) is returning null. Despite trying various solutions such as setting NEXT ...

What is the best way to address background-image overflow on a webpage?

I'm facing a challenge in removing the overflow from a background-image within a div. There are 4 divs with similar images that combine to form one background image (I adjust the position of each image so they align across the 4 divs). Essentially, I ...

What steps can I take to guarantee that a select change event occurs following the setting of ngmodel in Angular2?

I am facing an issue with a select element wherein a basic (change) handler is attached along with an ngmodel. Whenever an <option> with a ng value is set, the change handler triggers before the [(ngModel)] reflects the new values. <div> ...

I am having an issue in React.js where my state is not updating until the second click instead of the first one

Whenever I click items on my dropdown menu, the state only updates after clicking twice. I have provided a video and some code snippets for reference. How can I resolve this issue? https://i.sstatic.net/LkXUx.gif Parent Class Component (APP): class App e ...

Converting Emoji to PNG or JPG using Node.js - What's the Procedure?

Currently, I am working on a project that requires me to create an image file from emoji characters, preferably using Apple emoji. Initially, I thought this task would be simple to accomplish, but I have encountered obstacles with each tool I have tried. ...

The animation glitches out when attempting to update the color of the imported model

I'm facing an issue with a Blender model that has animation. After uploading it to the site, the animation works perfectly. However, I'm trying to change the body color of the model, and when I attempt to do so, the body stops animating and becom ...

Node.js npm-migration enables the creation of multiple tables in a single migration process

I am new to npm-migration for nodejs and I am exploring ways to streamline the process of creating multiple tables using a single migration, rather than having separate migrations for each table creation. I have experimented with the following code: "up": ...

Enhancing User Experience with Jquery Dialog and Implementing Stylish Text Presentation

My goal is to design a customer support dialogue that includes a title and two lines of text. The first line should display an error message, while the second line will feature a bold customer service number. To provide further clarity, I have created a vi ...