AngularJS grid designed to emulate the functionalities of a spreadsheet

I have been facing challenges with Angular while attempting to recreate a spreadsheet layout in HTML using ng-repeat. Despite extensive research, I have not found a solution.

My goal is to display data in a table format as shown below:

<table>
  <tr>
    <th>Account</th>
    <th>Jan</th> 
    <th>Feb</th>
    <th>Mar</th>
    <th>Apr</th>
    <th>May</th>
  </tr>
  <tr>
    <td>Sales</td>
    <td>50</td>
    <td>150</td>
    <td>250</td>
    <td>350</td>
    <td>450</td>
  </tr>
  <tr>
    <td>Variable Costs</td>
    <td>150</td>
    <td>250</td>
    <td>150</th>
    <td>150</td>
    <td>250</td>
  </tr>
</table>

There are 3 key elements that I need to incorporate into the table.

While I can easily create the columns using ng-repeat, my JSON data structure looks like this:

["Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"]

and my Angular code snippet is shown below: Account Description {{value }}

I'm also able to generate the rows using another JSON array:

["Sales", "Variable Costs", "Advertising"]

      <tr ng-repeat="(header, value) in tm1rows" >
        <td>{{value }}</td>

However, I am struggling to populate the table cells with values corresponding to a specific Account and Month combination from the provided JSON:

Example JSON data:

[{
        "account2": "Sales",
        "month": "Jan",
        "TM1CubeValue": 9090
    },
    {
        "account2": "Variable Costs",
        "month": "Jan",
        "TM1CubeValue": null
    },
    {
        "account2": "Sales",
        "month": "Feb",
        "TM1CubeValue": null
    },
    {
        "account2": "Sales",
        "month": "Feb",
        "TM1CubeValue": 1999
    },
    {
        "account2": "Variable Costs",
        "month": "Feb",
        "TM1CubeValue": 99
    }
]

Any assistance on how to solve this issue would be highly appreciated.

I believe I have provided sufficient information, but I am willing to provide more details if necessary.

Cheers!

Answer №1

After adjusting your data according to the comments in the question, you can utilize ng-repeat along with filters to populate the table and apply filtering based on the 'account2' type in both the th and td elements as demonstrated below:

 <table>
    <thead>
      <tr>
        <th>Account</th>
        <th ng-repeat="i in months">{{i}}</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Sales</td>
        <td ng-repeat="i in tableData | filter : {'account2' : 'Sales'}">{{i.TM1CubeValue}}</td>
      </tr>
      <tr>
        <td>Variable Costs</td>
        <td ng-repeat="i in tableData  | filter : {'account2' : 'Variable Costs'}">{{i.TM1CubeValue}}</td>
      </tr>
    </tbody>
  </table>

Remember to store your months array and actual data in dedicated $scope variables.

app.controller('MainCtrl', function($scope) {

  $scope.months = ["Jan",
    "Feb",
    "Mar",
    "Apr"];

  $scope.tableData = [{
    "account2": "Sales",
    "month": "Jan",
    "TM1CubeValue": 9090
  }, {
    "account2": "Variable Costs",
    "month": "Jan",
    "TM1CubeValue": null
  }];
});

An interactive example can be found in this Plunker.

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

How to trigger a submit action on a different page from an iframe using PHP

Is there a way to submit the iframe page using the modal's submit button in Page1.php to trigger the submit button of Page2.php? I need help executing this efficiently. The purpose of having the submit button in a modal is to perform multiple functio ...

Learn how to dynamically chain where conditions in Firebase without prior knowledge of how many conditions will be added

Currently, I am working on a project using Angular and firebase. My goal is to develop a function that can take two arguments - a string and an object, then return an Observable containing filtered data based on the key-value pairs in the object for a spe ...

How can you securely transfer the ARRAY OBJECT from JavaScript to PHP using Ajax?

I am attempting to send a Javascript Array Object via Ajax to PHP and then use that object as a true Array on the PHP side. My current approach has not been successful in terms of utilizing the incoming object as an Array within PHP; I can only parse it as ...

Converting JSON data to a pandas DataFrame requires the list indices to be integers

I have a large JSON dataset that I want to convert to CSV for analysis purposes. However, when using json_normalize to build the table, I encounter the following error: Traceback (most recent call last): File "/Users/Home/Downloads/JSONtoCSV/easybill.py" ...

Implementing AngularJS ng-click to dynamically add a duplicate Div or Widget with every click

The code below showcases a series of divs displayed one after the other: <ul class="record"> <li id="{{record.id}}" ng-repeat="record in records"> <div> Widget Code.... </div> </li> </ul> In addition to th ...

What is the best way to conceal an HTML element on a particular page that is already styled as (visibility: visible), but only if its child has a specific class assigned to it?

I have a grid of content and posts displayed on multiple webpages. Users can select specific items from the grid to navigate to more detailed information on another page. Each webpage has its own grid which I want to filter based on a specific class. The ...

Customizing row colors in AngularJS ui-grid

I'm facing issues with setting colors for specific rows in Angular ui-grid. I am aware that I can utilize a row template as shown below. However, the "row.sequence" attribute is not working as expected. Could someone provide me with code example ...

Learn how to effectively showcase various components by leveraging the new react-router-dom v6.0.0 alongside react-redux

My issue is that when I click on a link to render different components, the URL updates but the UI remains unchanged. No matter which item I click on to render, the same thing happens. I've tried numerous solutions to fix this problem without success. ...

Pattern Matching: Identifying partial or complete text

Currently, I'm facing challenges with a small script that is designed to compare the value from a text input with items in an array either partially or completely. I am struggling specifically with the regular expression and its syntax. I was hoping ...

Transfer of part of a JSON object

My current setup involves an API in PHP that sends JSON data to a Javascript webpage for processing. However, when dealing with large datasets, it can strain both the user's internet connection and computer capabilities. To address this issue, I want ...

Create a dynamic process that automatically generates a variety of div elements by using attributes from JSON data

Is there a way to organize the fixtures from this data into separate divs based on the matchday attribute? I've tried using Underscore's groupBy function but I'm unsure how to dynamically distribute the data into individual divs for each re ...

Having trouble executing Angular jasmine test using grunt karma?

I've been through the process of installing and reinstalling grunt, karma, and jasmine multiple times, but I'm still encountering the issue described below. When I run the test in Jasmine on its own, everything works perfectly fine. It doesn&apos ...

Manipulating Objects with CSS Transform in Global/Local Coordinates

If we take a closer look at our setup: <div id="outside"> <div id="inside">Foo</div> </div> and apply a rotation to the outer element - let's say turning it 45 degrees clockwise: <div id="outside" style="transform: ro ...

Adjust the width to ensure the height is within the bounds of the window screen?

I am currently in the process of developing a responsive website, and my goal is to have the homepage display without any need for scrolling. The layout consists of a 239px tall header, a footer that is 94px tall, and an Owl Carousel that slides through im ...

Encountering a CORS issue specifically on the client side of a Next.js application when interacting with an API gateway

I've been struggling with this issue for a week now and can't seem to fully describe it. I have a FastAPI server running as a Lambda connected to API Gateway. https://i.stack.imgur.com/S5Zx9.png Both FastAPI and API Gateway have CORS enabled, b ...

Highchart tip: How to create a scrollable chart with only one series and update the x-axis variable through drilldown

Before I pose my question, here is a link to my jsfiddle demo: http://jsfiddle.net/woon123/9155d4z6/1/ $(document).ready(function () { $('#deal_venue_chart').highcharts({ chart: { type: 'column' ...

Execute a JavaScript function when a form is submitted

Seeking to reacquaint myself with Javascript, encountering difficulties with this fundamental issue. https://jsfiddle.net/gfitzpatrick2/aw27toyv/3/ var name = document.getElementById("name"); function validate() { alert("Your name is " +name); } < ...

Encountering a "Connection Refused" error when attempting to test a React and Express application

Currently, I am developing an order system using React for the frontend (port 3000) and Express for the backend (port 3001). Everything functions perfectly when tested on the same MacBook that hosts the node project. However, when testing it on a differen ...

Exploring the power of Vue element manipulation

I'm diving into the world of web development and starting my journey with Vue on an online learning platform. Check out the code snippet below: <div id="app"> <form @submit.prevent="onSubmit"> <input v-model="userName"&g ...

Using Typescript with d3 Library in Power BI

Creating d3.axis() or any other d3 object in typescript for a Power BI custom visual and ensuring it displays on the screen - how can this be achieved? ...