Tips for emphasizing the row with the highest cell value in an Angular UI Grid

My Angular UI Grid setup includes:

 var rowtpl='<div ng-class="{\'extremum\':row.entity.threads==150 }"><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader }" ui-grid-cell></div></div>';

    $scope.gridOptions = {
        enableHorizontalScrollbar: 0,
        enableSorting: true,
        enableFiltering: true,
        enableColumnResizing: false,
        enableRowSelection: true,
        enableRowHeaderSelection: false,
        multiSelect: false,
        noUnselect: true,
        onRegisterApi: function (gridApi) {
            $scope.gridApi = gridApi;
            gridApi.selection.on.rowSelectionChanged($scope, function (row) {
                if (row.isSelected) {
                    var importedData = row.entity;
                    DataService.selectedImportedDataId = importedData.id;
                    $scope.selectedData = importedData;
                }
            });
        },
        columnDefs: [
            { name: "Run", field: "run" },
            { name: "Time of Day", field: "tod" },
            { name: "Rate", field: "rate" },
            { name: "MB/sec", field: "mbps" },
            { name: "Response", field: "resp" },
            { name: "xfersize", field: "xfersize" },
            { name: "Threads", field: "threads" },
            { name: "queue_depth", field: "queue_depth" },
            { name: "Read %", field: "read_percentage" },
            { name: "Read response", field: "read_resp" },
            { name: "Write response", field: "write_resp" },
            { name: "lunsize", field: "lunsize" }
        ],
        data: [],
        rowTemplate: rowtpl
    };

(The data is loaded separately from this code). Below is the HTML where Testcontroller is the name of my controller.

 <div ng-controller="TestController" class="row">
    <div class="container-fluid">
        <div class="row">
            <div ui-grid="gridOptions"
                 ui-grid-edit
                 ui-grid-auto-resize
                 ui-grid-selection
                 ui-grid-save-state>
            </div>
        </div>
    </div>
</div>

This implementation creates a table with a highlighted row based on a condition (row.entity.threads==150 in the row template). Now, I'm exploring options to automatically highlight rows with either the maximum or minimum value. Any insights on achieving this would be appreciated!

Answer №1

Give this method a try.

Here is your Row template:

var rowtpl='<div ng-class="{\'extremum\':row.entity.threads==150, \'highlight\':row.entity.isMaximum }"><div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ \'ui-grid-row-header-cell\': col.isRowHeader }" ui-grid-cell></div></div>';

Make sure to include the highlight class in your CSS. When fetching data, iterate through it to identify the maximum value and set a flag entity.isMaximum = true.

To find the maximum value in your data array, you can utilize a maximum-finding function in JavaScript. One option is using UnderscoreJS. An example implementation is shown below.

var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];
_.max(stooges, function(stooge){ return stooge.age; });
=> {name: 'curly', age: 60};

If you encounter any challenges with this solution, kindly share your data object for further assistance.

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

The corner of cubes in Three.js is unfortunately not visible

After setting up an Orbital Controls with a boxGeometry to display a box, I encountered an issue where the corners of the box were not being rendered properly when zoomed in. My current setup involves using react-three-fiber and react-three-drei const Sce ...

Expanding Module Scope to Just the Request (employing Require, Node.js)

Original Query The project I am currently working on is using Express to manage HTTP requests. The structure of the project is quite intricate, with multiple embedded require statements. Our main challenge lies in maintaining access to the request and re ...

When attempting to run HTML and JavaScript files locally, an error is encountered: "TypeError: The module name 'openai' is not resolving to a valid URL."

As a beginner in web development, I decided to follow a tutorial on creating a web application using the OpenAI API. The tutorial instructor runs the code in an environment called Scrimba, but I am working on my MacBook. This is how the app functions: it ...

Retrieve container for storing documents in JavaServer Pages

Previously, I created JSP and HTML code to upload a file from the hard disk into a database using <input type="file" name="upfile"> However, a dialog box with an "Open" button is displayed. What I am looking for is a "Save" button that will allow u ...

What is the best way to remove a particular element from an array stored in Local Storage?

Currently working on a web application that features a grade calculator allowing users to add and delete grades, all saved in local storage. However, encountering an issue where attempting to delete a specific grade ends up removing the most recently add ...

Encountered an issue while trying to synchronize with the page using Protractor: "Unable to find window.angular"

I am relatively new to using Protractor and have successfully created several page objects. So far, everything has been working smoothly. However, I recently encountered an issue after logging in to a page and being redirected to the myaccount page. Upon ...

Is there a way for me to conduct multiple counts and choose the highest one especially if they are all promises?

Here is my voting controller for a post. If the user has not already voted on the post (their voterId is not in the votes array), their vote is added by adding their voterId to the votes array of the post. The voteCount is then reset to the length of that ...

Create a loop that depends on the user's ID

Utilizing node, express, and swig, my goal is to create a loop based on the currentUser local variable. Although I have managed to get the loop working, it currently displays results for every user. Below is the loop I am using: {% for ap in aps %} ...

Exploring JSON parsing using javascript?

I'm currently attempting to work through this webRTC example and have encountered an issue that appears to be minor in nature... The if statement consistently fails to return true, despite the fact that the console message indicates that the property ...

What are the restrictions of using the Angular orderby array function?

Is there a restriction on the number of values in an Angular orderby predicate? I am having trouble getting anything with more than 2 fields to function properly. It seems that anything after the 2nd index does not work. However, if I rearrange the fields ...

Creating a visually appealing legend for the axes of a line chart in D

The d3.js line chart I created displays axes with units like 0m, 1m, 2m, 3m and so on for various measurements. I would like to include a legend near the chart to explain these units, such as m = milli, n = nano, B = billion, etc. ...

Adjust the width of the inline textarea using HTML and CSS to match that of the input field

Is it possible to create an inline textarea element using CSS that is selectable but still seamlessly integrated into a sentence without specifying the number of columns? Here's an example with a static number of characters (cols="11"): <p>To r ...

What is the best way to incorporate an "or" operation into the loop structure?

Is there a way to loop the code provided below while keeping the column names in the array and returning by loop? return Students.filter((singleItem) => { singleItem["id"].toLowerCase().includes(value.toLowerCase()) || singleItem[" ...

Knockout JS: Choosing specific dropdown elements

My array doorsForSite contains a list of doors, each with its own set of schedules. Here is how it looks: var scheduleList = new[] { new { ScheduleId = "Schedule1",ScheduleName = "Always On" }, new ...

Unable to integrate Express.js into my React JS project

Having trouble integrating express.js into my react js Project. After adding the following lines to my app.js code: const express = require('express') const app = express(); I encounter the error messages below: - Module not found: Error: Can&ap ...

retrieve all images using ajax

function checkallfolder(){ var thumbnailbox = $('#thumbnailbox'); var foldertype = ["img1", "img2", "img3", "img4", "img5", "img6", "img7"]; for (var c = 0; c < foldertype.length; c++ ){ var folder = 'Img/dfolder/'+folderty ...

What is the best way to implement two separate fonts in a document using the Monaco editor?

I have implemented react-monaco-editor in my project. In the overall CSS, I have defined a font family to be used as Helvetica, Tahoma, Arial, monospace. However, I also need to customize the font for a specific editor instance on the page to be "Fi ...

How can I populate an array with objects from a different array in Javascript using AngularJS?

Currently, I am facing a challenge in my angularjs application. I have a huge array containing the cast of a movie, which includes directors, producers, and film crew members. My goal is to create a new array specifically for the director(s). I am unsure ...

Is it possible to connect to the Oculus Go controller using the GamePad API within the Oculus Browser

Exploring my three.js apps on the new Oculus Go has led me to question whether I can interact with the controller solely through the GamePad API supported by major browsers. Although Oculus documentation suggests using OVRManager in Unity or Unreal Bluepri ...

Adjusting the "this.var" variable within the Controller does not affect any changes

Apologies for my poor English. I have been exploring the use of controllerAs as Namespace and 'this' instead of $scope Here is a brief example: <html ng-app="MyApp"> <head> <script src="https://ajax.googleapis.com/ajax/lib ...