Finding the sum of values in the aggregate row of an ng-grid table

In my ng-grid, I have organized metrics from three different computers into columns named name, value, and machine. Instead of displaying three lines for each metric, I utilized the groups: ['name'] setting in the gridOptions. However, I am struggling to determine how to show the sum of the values in the aggregate row. Is there a method to access the row values within each group to calculate this sum?

This is the desired result (7, 10, 4, 6 displayed on the aggregate rows in the value column):

  NAME           VALUE     MACHINE
v metric1 (3)    7
  metric1        3         comp-a
  metric1        2         comp-b
  metric1        2         comp-c
> metric2 (3)    10
> metric3 (3)    4
v metric4 (3)    6
  metric4        5         comp-a
  metric4        0         comp-b
  metric5        1         comp-c

I appreciate any assistance you can provide!

Answer №1

I faced the same issue and attempted some suggested solutions without success due to compatibility issues with my grid version. After delving into the grid's source code, I identified the template used for aggregate rows, duplicated it, and modified it to incorporate a call to a function within my method for parts of the presentation:

Within my gridOptions, I specified the following property

aggregateTemplate: "<div ng-click=\"row.toggleExpand()\" ng-style=\"rowStyle(row)\" class=\"ngAggregate\">" +
    "    <span class=\"ngAggregateText\"><span class='ngAggregateTextLeading'>{{row.totalChildren()}} {{row.label CUSTOM_FILTERS}} {{entryMaybePlural(row)}}</span><span>Total Weight: {{aggFunc(row)}} lbs {{AggItemsLabel}}</span></span>" +
    "    <div class=\"{{row.aggClass()}}\"></div>" +
    "</div>" +
    ""

Within the controller scope for the grid, I implemented the functions

  $scope.aggFunc = function (row) {
    var total = 0;
    angular.forEach(row.children, function(cropEntry) {
      total+=cropEntry.entity.weight;
    });
    return total.toString();
  };
  $scope.entryMaybePlural = function (row) {
    if(row.children.length>1)
    {
      return "entries";
    }
    else
      return "entry";
  };

In both instances, the row is passed from the template to the function within the controller scope, where I access the children property of the row (discovered through Chrome debugging tools after previous attempts failed).

PS: The top of my grid includes this compilation note, albeit without indicating a specific version :|

/***********************************************
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md 
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 06/03/2013 21:19
***********************************************/

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

Having trouble sending an HTTPS request in NodeJS only to receive an HTTP response instead

As I develop my website using NodeJS and deploy it on Heroku, I encountered an issue upon opening the website. Here is the problem at hand: When looking at the main source file of my web application: app.get('/', (req, res) => { var data ...

Generating individual div elements for every piece of data in ReactJS with the help of Redux

I am utilizing redux to manage the data within a React application. Each block of data is displayed within its own DIV element. My goal is to have each div separated by space and transformed into an accordion card. I am seeking guidance on the best appro ...

`There is a delay in rendering the background image on Chrome`

Once I apply a class to my button element using JavaScript, the background image (.gif) that is supposed to display afterwards takes an unusually long time to render. The button serves as a form submission. Upon being clicked, a class of "clicked" is dyna ...

How can you utilize Angular Signals in combination with HostBinding to dynamically update styles?

Within a component called app-test, the following code is present: @Input({ transform: booleanAttribute }) reverse: boolean = false; @HostBinding('style.flex-direction') direction: string = this.reverse ? 'column-reverse' : &ap ...

What is the best way to define a function in React hooks - using a function statement or

When working with a react hook and needing to define a function inside it, which approach is preferable? useEffect(() => { //... function handler() {} //... }, []); or should I use the newer const declaration instead? useEffect(() => { ...

Loading STL files from a buffer instead of a path within Three.js

I'm struggling to showcase a user-uploaded STL file in Three.js. The issue arises when my file is delivered to the front-end through a GET request: res.sendFile(path). Unfortunately, I can't directly utilize this raw data to load the file withou ...

Puppeteer cluster crashes unexpectedly upon invoking cluster.close() following cluster.queue() execution

So here's the deal - I developed an app for web scraping that requires the ability to run multiple processes simultaneously (more than one Chromium instance). To achieve this, I implemented puppeteer-cluster. While I successfully managed to initiate s ...

Switching images through onmouseover, onmouseout, and onclick interactions

I have two images named img1 and img2. Here is my code: function roll(id, img_name, event_name, img_id) { var state ; if(event_name == 'mouseover') { state = false;rollover();} else if(event_name == 'mouseout') { ...

Modifying property values using the onError event when encountering an error with the MUI DateTimePicker and

My goal is to set the 'myError' variable to true when MUI DateTimePicker throws an onError event, but for some reason it's not working. The code itself seems correct because if I replace () => {setValue({ ...value, ...

Is there a way to position one DIV behind another?

Hey, I'm working on my first project and running into some trouble with divs. I'm trying to position the firework behind the central text but can't figure it out. Can anyone lend a hand? I need to add more details in order to submit the que ...

Angular2 Window Opener

Trying to establish communication between a child window and parent window in Angular 2, but I'm stuck on how to utilize window.opener for passing a parameter to Angular 2. In my previous experience with Angular 1.5, I referenced something similar he ...

My goal is to monitor every action (button) that users take while using the PDF viewer

Each browser displays the view differently, and I am interested in monitoring specific user actions such as button presses on a PDF viewer. I am currently setting up an iframe and configuring its attributes. Is there a way to achieve this? ...

What is the best way to send data to a component through a slot?

Currently, I am working on a Vue application that utilizes pimcore and twig in the backend. My task involves creating a component that can receive another component (slot) and dynamically render it with props. Here is the root structure found in viani.twig ...

What is the reason for my result showing as Object { } rather than MyObj { }?

When utilizing the web development tools console, if a browser object is typed, it will return as "console." > console Console { } > console.log(console) undefined > Console { } This behavior applies to all browser objects. However, when I try ...

Error in Typescript: Function not being triggered on button click

As someone who is just starting out with typescript, I've been tackling a simple code that should display an alert message in the browser when a button is clicked. I've experimented with the button and input tags, as well as using both onclick ev ...

Transitioning the Background Image is a common design technique

After spending hours trying to figure out how to make my background "jumbotron" change images smoothly with a transition, I am still stuck. I have tried both internal scripts and JavaScript, but nothing seems to work. Is there any way to achieve this witho ...

Error: Unable to access the property 'fn' of an undefined object in electron version 2 using Angular 6

I am currently utilizing Angular 6.0.3 and electronjs 2.0.2 with the package.json configuration shown below: { "name": "test", "version": "1.0.0", "license": "MIT", "main": "electron-main.js", "author": { "name": "Moh ...

Is it logical to combine Require.js and Angular.js for web development purposes?

As someone new to Angular.js, I am exploring how it differs from Backbone.js. Previously, we utilized Require.js to handle our package dependencies with Backbone. Is it advisable to follow the same approach with Angular.js? ...

Phaser 3 game app on iOS generated with Capacitor lacks audio functionality

I have developed a basic test app using Phaser 3 (written in Typescript and transpiled with rollup) and am utilizing Capacitor to convert it into an iOS application on my Mac. This excerpt highlights the key functionality of the app: function preload () { ...

What steps can be taken to address the build problem with Angular version 13?

Encountering a problem while working with Angular 13: https://i.sstatic.net/CbAUhh6r.png Attempting to build using ng build --configuration=test, however facing errors as mentioned above. Interestingly, if I remove the reference to bootstrap.min.css in t ...