Leverage the power of Angular.JS and ng-table to effectively summarize values in your

I received the following JSON data:

 var   scholars = [{"FirstName":"John","LastName":"Doe","Unit":"PA","Institution":"University of Haifa","teken":1,"FirstYearActive":"2007","hIndex":"3","j2014":0,"j2013":4,"j2012":3,"j2011":0,"j2010":0,"j20052009":2,"j20002004":0,"j19901999":0,"jPriorto1990":0,"ab2014":0,"ab2013":0,"ab2012":0,"ab2011":0,"ab2010":0,"ab20052009":0,"ab20002004":0,"ab19902000":0,"abPriorto1990":0,"c2014":5,"c2013":10,"c2012":7,"c2011":0,"c2010":3,"c20052009":2,"c20002004":0,"c19901999":0,"cPriorto1990":0,"b2014":0,"b2013":0...

I am seeking to total all instances of j2014 using this code snippet:

var j14sum = 0;
      for (var i in scholars){
        if (scholars[i].Institution == "University of Haifa")
          j14sum += parseInt(scholars[i].j2014);
      };

How can I implement this with angular.js and display the results using ng-table?

Appreciate any assistance!

Answer №1

After some troubleshooting, I managed to identify a solution for the problem at hand.

let summary = data.reduce(function(dictionary,item){
    if(!(item.ID in dictionary)){
        dictionary[item.ID] = {
            ID:item.ID,
            count: 0
        };
    }
    dictionary[item.ID].count += parseInt(item.count);
    return dictionary;
},{});

You can view the code snippet on this fiddle: http://jsfiddle.net/abc123xyz/8/

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

Need to double tap to remove item in redux-toolkit

Trying to delete an item in Redux Toolkit, but having trouble as the remove function only works on screen. I have to press twice to delete the previous one. Here is the reducer: const noteReducer = createSlice({ name: "note", initialState: N ...

Having difficulty initializing jQuery DataTables upon button click with an Ajax request

I have a piece of HTML code that represents a partial view: <table id="table_id" class="table table-inverse"> <thead class="thead-inverse"> <tr> <th>Select</th> ...

How to access webpack's require.context feature on the development server

In my webpack development configuration, I have set up a mocked backend using Express. Following an example from the DevServer Docs, my setup looks something like this: module.exports = { // ... devServer: { setupMiddlewares: (middlewares, devServe ...

Tips for adjusting the material ui Popper width to fit the container without disabling the portal

Currently utilizing the material-ui popper library. I am trying to allow the popper to extend outside of its container in the vertical direction. To achieve this, I have set disableportal={false}. However, upon setting disableportal to false, when assign ...

Using shortcode to enhance wordpress post content

I am trying to implement a feature similar to the one found at http://jsfiddle.net/theimaginative/gA63t/ within a wordpress post. I have attempted to create a shortcode for inserting this into a post, but I am encountering difficulties. While I have been s ...

Searching for text using JQuery autocomplete feature with results fetched from an external source

I am currently working on integrating an input field with autocomplete functionality using the Google Books API to suggest book titles based on user input. My framework of choice for this implementation is Django. So far, I have managed to achieve the fol ...

Showing information from asynchronous AsyncStorage.getItems in React Native

In my app, users have to validate their success on challenges by clicking a validation button which saves the "key":"value" pair of the challenge using this function: async function validate(challenge_nb) { try { await AsyncStorage.setItem(challenge_n ...

Is there a way to exclude certain URLs from the service worker scope in a create react app, without the need to eject from the project?

Is there a way to remove certain URLs from a service worker scope in create-react-app without needing to eject? The service worker is automatically generated, and it seems impossible to modify this behavior without undergoing the ejection process. ...

Is it possible to save edits made to CKEDITOR by clicking a button located outside of the editor?

I am having an issue with inserting HTML code into my CKEDITOR. I have a button on the page that, when clicked, calls: editor.insertElement(link); After inserting the HTML code correctly into the editor, any changes made (such as clicking the 'show ...

The issue with single quotes causing problems in JSON when generated from PHP

IMPORTANT: I initially had a different question in mind, but I've now pinpointed where the actual issue lies. The current problem I'm facing involves generating JSON output from PHP for jQuery use across domains using "JSONP." The culprit seems ...

"Stellar.js fails to function properly when applied to elements loaded dynamically through AJAX requests

I recently implemented the amazing Stellar.js for parallax effects in a project of mine. However, I've encountered an issue: Stellar.js does not recognize when I update content via AJAX (specifically loading new div elements from an HTML file and rep ...

Creating a Dynamic Tree View Component in AngularJS Using JSON Data

I am new to AngularJS and I need help creating a TreeView Structure from a JSON Object. Here is an example of my Return JSON Object: var categoryTree = [{Name:'Item1', Childnodes : {}, id: 1}, {Name:'Item2', Childnod ...

Mastering Number Formatting in VueJS

While working with VueJS, I encountered difficulties in formatting numbers the way I wanted. After exploring options like the builtin currency filter and vue-numeric, I realized they required modifications to achieve the desired look. Furthermore, these so ...

What is the best method for showcasing the parsed JSON data in a list view?

Hello, I am new to Android and seeking some guidance. I have two buttons - one for getting JSON data and the other for parsing it. While the first button is working fine, the second one doesn't display the list view as expected. I specifically want t ...

Empty data payload for custom WP API endpoint

I've encountered a frustrating issue that's really got me scratching my head. It seems to be something minor that I just can't seem to figure out. Here's what's happening: I'm trying to make a POST request to a custom API en ...

The element is being offset by SVG animation that incorporates transform properties

I'm working on creating a halo effect by rotating an SVG circular element using the transform rotate function. I've been using getBox to find the center point of the element, but when the rotation occurs, the overall image is getting misaligned w ...

What is the best method for determining the ID or class of a div element dynamically?

My issue involves a scrolling div that dynamically loads data using ajax and json from an API as you scroll horizontally. Currently, I have multiple scrolling divs on a single page. The problem arises when I need to inform jQuery about the ID of the div b ...

Picasso's image cache in Android is failing to clear

I am having trouble with maintaining the image cache even after editing it. The code I am using to load an image from Json into an imageView is shown below: Picasso.with(Sell_Preview_Activity.this) .load(Httppost_Links.imagePath ...

A guide on determining if a JSON data array yields a value or is empty

I've been attempting to determine if an element of an array contains empty data using jQuery, but it's not working as expected. When the value passed exists in the database, the array values are returned. However, when the passed value is incorr ...

Guide on automatically navigating pages using HTML

My dilemma involves two HTML pages: flash.html main.html I am seeking a solution where the flash.html page is loaded first for 5 seconds, after which the main.html page should automatically load. How can I achieve this? I attempted to use setTimeout(fu ...