How to prevent table row from highlighting on hover in Angular Bootstrap

In my project, I have a table that showcases various details and allows users to select certain rows. Some of these rows have child rows which can also be selected.

The requirement is for the parent rows to be selectable only if they do not have any children. If they do have child rows, then only the child rows should be selectable. Essentially, it's a 'select-only-one' type of table.

The current setup functions correctly in terms of row selection. However, there's a need to disable hover functionality on parent rows that are not selectable.

If you want to see how this works, check out this live example: http://plnkr.co/edit/Z0cgHKx2qxpekEE36O1K?p=preview

Below is a snippet from the controller showcasing part of the code:

    scope.parentSelected = [];
$scope.childSelected = [];

$scope.getParentDetails = function(parentObj) {
  if(!parentObj.jobs || parentObj.jobs.length === 0) {
    nonSelectOtherRows(); 
    var index = $scope.pro.indexOf(parentObj);
    $scope.parentSelected[index] = !$scope.parentSelected[index];

    // get details for parent row using parentObj
    console.log(parentObj);
  } 
};

$scope.getChildDetails = function(parentObj, childObj) {
  nonSelectOtherRows();
  var parentIndex = $scope.pro.indexOf(parentObj);
  var childIndex = parentObj.jobs.indexOf(childObj);
  $scope.childSelected[parentIndex] = [];
  $scope.childSelected[parentIndex][childIndex] = !$scope.childSelected[parentIndex][childIndex];

  // get details for parent and child rows using parentObj and childObj.
  // childObj is the childRow selected
  console.log(parentObj);
  console.log(childObj);
}

Answer №1

Get rid of the table-hover attribute.

Create your own functions for ng-mouseover and ng-mouseleave.

$scope.hoverIn = function(row){
   row.hoverEdit = true;//check if selectable or not
};
$scope.hoverOut = function(row){
   row.hoverEdit = false;
};

Define a CSS class for hovering effect.

.custom-hover {
  background-color: red;
}

Lastly, add the class to your tr element.

`'custom-hover': x.hoverEdit`

Check out this link for an example: http://plnkr.co/edit/CJxi86GyM8jMbtehPQgU?p=preview Include your selectable control inside hoverIn function for it to work correctly.

Answer №2

Give ng-class a try, it can definitely assist you.

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

Ajax: setInterval function successfully runs code but does not refresh the HTML output

I have multiple div elements in my code. I want to update the HTML content inside them based on an API request. The updating process works fine, but the HTML content doesn't refresh visually (meaning that even if I receive a new result from the API, t ...

What could be causing my Express server to return a 404 error when trying to submit the form, all while failing to display any console

Having trouble setting up multi-user sessions similar to Google Docs, but my server file seems unresponsive. I've double-checked my fetch function and ensured it is accurate, yet no changes are occurring. Even console.logs from the server file command ...

React Native displaying identical path

Is there a way to dynamically change routes in React Native when a button is pressed? Inside my SplashContainer component, I have the following method: handleToSignUp = () => { console.log("Running handleToSignUp") this.props.navigator.push({ ...

I would greatly appreciate your assistance in deciphering the JavaScript code provided in the book "Ajax in Action"

While reading through the Ajax in Action book, I came across a code snippet that has left me with a couple of questions. As someone who is new to web programming and still getting to grips with JavaScript, I am hoping for some clarity on the following: ...

How to fetch select element within a table by using jQuery

I encountered a situation where I have a table element with a select element inside its td. The id of the table (in this example, it is "table1") could potentially change. So my query is, how can I retrieve the selected option using the table ID in JQuer ...

I encountered an SyntaxError while working with Ionic. The error message reads: "Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>)."

Here's the code that is causing me trouble: this.http.get('http://localhost/....) .map((res) => res.json()) .subscribe(( this.navCtrl.push(OtpPage,{mobileno:this.mobile}); }, (err) => { console.log(err ...

The CSS cubic-bezier fails to smoothly transition back to its initial position

I created an animation that works perfectly when hovering over the target elements, however, it doesn't smoothly transition back to its original position when the cursor moves outside of the target element. Instead, it snaps back abruptly and unattrac ...

Issues with Font-Face Implementation

Hey there! I'm currently working on incorporating a new font into my website using font-face. However, it seems like something might be missing from my code because the style isn't being applied correctly. Here is what I have so far: <div id= ...

How do I go about configuring the uploaded image?

Here is a sample of my HTML code: <div class="images"> <figure> <button id="upload-add-product" class="icon-plus"></button> <input id="upload-file" type="file" style="display: none;" multiple/> </fi ...

Combining Data from Header to Body using HTML5 and JavaScript

I am struggling to figure out how to transfer variables declared in the script from the header of my code to the body. Specifically, I want to capture the user input in the script and replace a placeholder in the body. Here is an example of what I am tryin ...

Manipulate documents in a Mongoose array by conditionally adding or removing elements

Upon receiving data from the front end, I am dealing with the following object: { name: "Test 1", sets: [1,2] } Mongo Schema: Sets name: { type: String }, tests : [{ type: Schema.Types.ObjectId, ref : 'Test' ...

Managing Input Type Dropdown Selections Using Jquery

I am currently in the process of developing a website. On this website, there is a form that includes 3 dropdown menus as shown below. I would like to implement a feature where selecting the number 5 from the Adults menu will automatically display 5 in the ...

Function for masking phone numbers is adding additional "x's" to the input field

My phone number formatting script is supposed to add dashes after the third and sixth characters, as well as insert an "x" after the 10th character for extensions. However, it is adding extra "x's" after the 12th character, resulting in the incorrect ...

What is causing the ajax code to malfunction?

I am new to ASP MVC and trying to create a login form using AJAX. I have written a JsonResult in the controller to check the username and password, but for some reason it is not working. Here is my controller code: public ActionResult login() { ...

Send the function with parameters, but do not pass its output

Within my component, there is a need property that holds a static function. This function is executed by middleware to handle asynchronous API calls before rendering the component. Here's an example: static need = [ myFunc(token) ] The issue arise ...

Enhance your user experience by implementing a jQuery solution that makes a div

Looking to add a small div on the right side of your screen that moves along with your vertical window slider? Wondering if jQuery has a function to get the current vertical slider position? I thought scrollTop() might work, but it only returns from a spe ...

The Angular scope fails to reflect changes on the view

In this angular ng-click event, I have the following code: eventApp.controller('DetailEventController', ['$scope', '$http', '$compile', '$timeout', function ($scope, $http, $compile, $timeout, uiCalendarCon ...

Customize default zoom settings with Cascading Style Sheets (CSS)

body{ margin-bottom: 10%; margin-left: 10%; width:80%; color: #264653; position: relative; } #photo{ border-radius: 70%; position: absolute; left: 25%; top: 50px; } .left1{ margin-top: 10%; background-color: #264653; width : 30%; ...

Using PHP and JavaScript to determine device screen width and eliminate the $_GET parameters from the URL

I have implemented the following JavaScript code to detect screen width and utilize it as a constant throughout my template files using conditional statements to control the visibility of different sections on my site. Just to clarify, I am working within ...

retrieve the value of a text form using jQuery and its corresponding id

I need help with a basic HTML form that includes jQuery. My goal is to: 1) Retrieve the value into a JavaScript variable. 2) Send it as JSON to a server. Here is the form: <div data-role="main" class="ui-content"> <data=role "form" ...