Assign the colId to the pinnedBottomRowData property within Ag Grid

I'm facing an issue with displaying data in the pinned row within ag-Grid Vue 2. I am utilizing pinnedBottomRowData to supply data for the pinned row, but despite the pinned row being visible, it remains empty. The problem arises from using dot notation in the field property of my JSON file data, like this:

field: "supplier.number"
. Unfortunately,
this.gridApi.setPinnedBottomRowData
does not support dot notation, leading me to add
colId: "supplierNumber"
. However, even with this change, the issue persists. When I remove the dot notation and replace it with
field: "supplierNumber"
, it works fine. Sadly, modifying the JSON directly is not an option as the data comes from an external source.

The last resort would be creating a new object with the data from the JSON, though I prefer to avoid this workaround if possible. Can someone assist me with resolving this dilemma?

Below is my Code: Ag Grid

          <ag-grid-vue
            style="flex: auto; flex-direction: row; height: 650px"
            :class="cssClass"
            :columnDefs="columnDefs"
            :rowData="supplierList"
            :gridOptions="columnOptions"
            :alwaysShowHorizontalScroll="true"
            @grid-ready="onGridReady"
        ></ag-grid-vue>

Column Definitions:

   columnDefs: [
        {
          headerName: "Information",
          children: [
            {
              headerName: "Description",
              colId: 'supplierDesc',
              field: "supplier.desc",
            },
            {
              headerName: "number",
              colId: "supplierNumber",
              field: "supplier.number"
            },
          ],
        },
        {
          headerName: "Header2",
          children: [
            {
                  headerName: "Supplier Budget",
                  colId:"supplierBudget",
                  field: "year2024.budget",
                  cellRenderer: (params) => this.currencyFormatter(params.value, "€"),
            },

              ],}, ],

Function onGridReady

onGridReady(params) {
      this.gridApi = params.api;
      this.gridColumnApi = params.columnApi;

      this.createData('Total:', this.supplierList);
    },

This is the createData Function

  createData(prefix,list) {
      let calcTotalCols = ['supplierDesc', 'supplierNumber','supplierBudget'];
      let total = [{}];
      // initialize all total columns to zero
      calcTotalCols.forEach(params => { total[0][params] = 0 });
      // calculate all total columns
      calcTotalCols.forEach(params => {
        list.forEach(line => {
          total[0][params] += line[params];
        });
      });
      let result = [];

      result.push({
        supplierDesc: prefix + total[0]['supplierDesc'],
        supplierNumber: prefix + total[0]['supplierNumber'],
        supplierBudget: prefix + total[0]['supplierBudget'],
      });

      this.gridApi.setPinnedBottomRowData(result);
    },

Answer №1

If you want to avoid directly modifying the JSON data, you can implement a solution like the following:

generateData(prefix, dataList) {
  let calculationColumns = ['supplierDesc', 'supplierNumber', 'supplierBudget'];
  let accumulatedValues = {};
  calculationColumns.forEach(col => { accumulatedValues[col] = 0 });
  calculationColumns.forEach(col => {
    dataList.forEach(item => {
      const fields = col.split('.');
      let value = item;
      fields.forEach(field => {
        if (value && typeof value === 'object') {
          value = value[field];
        }
      });
      accumulatedValues[col] += value || 0;
    });
  });

  let finalResult = {};

  calculationColumns.forEach(col => {
    finalResult[col] = prefix + accumulatedValues[col];
  });

  this.gridApi.setPinnedBottomRowData([finalResult]);
},

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

What are the steps to ensure that this iframe adjusts perfectly to the page in terms of both vertical and horizontal dimensions

I have a sandbox from Material UI that you can view at this link: https://codesandbox.io/s/material-demo-forked-c8e39?file=/demo.js Upon loading the page, an iframe displays some HTML content. Although the width fits perfectly, there are two vertical scro ...

angular2 : problem encountered with communication to rest api

Transitioning from PHP to Angular2 has been quite challenging for me, especially when trying to use a real rest API like "Tour of Heroes". I initially thought it would be simple... Currently, I have set up a functional API with Express: curl -XGET http:/ ...

jquery plugin for creating Excel-like filters

I am in the process of creating Excel-like filtering for my dynamic table. To achieve this, I am utilizing a jQuery plugin that can be found at https://github.com/chestercharles/excel-bootstrap-table-filter. The reason why I chose this plugin is because it ...

The jquery selector fails to retrieve all elements

On the upcoming web page, I am attempting to use Jquery to select all <li> elements. Specifically, I want to target all the products contained within <ul class=search-result-gridview-items">. You can find the products here: I have made attempt ...

Issue with setting and showing the PHP data array within the vue.js variable

I am encountering an issue with transferring an array of data from a PHP session variable to a Vue.js variable Here is how I am trying to assign an array of data to a Vue.js variable: permissions:['<?php echo json_encode($_SESSION['permission ...

Tips for achieving expansion of solely the clicked item and not the whole row

I am trying to create a card that contains a cocktail recipe. The card initially displays just the title, and when you click on a button, it should expand to show the full menu and description. The issue I'm facing is that when I click on one element, ...

Having trouble generating JSON data within an asynchronous loop using Vuejs and FileReader?

A mechanism is required for users to submit multiple files through a Vue form component. Prior to sending the data to a remote JSON API endpoint, these files need to be processed. An attempt was made to address this by utilizing FileReader and an asynchro ...

Efficient management of jQuery variables

I am currently working on a form and I have been trying to change an input's type using jQuery. Thanks to the helpful resources available on this website, I learned that I need to clone and replace the input in order to change its type. However, I enc ...

Guide on linking an id with a trigger function in HTML and JavaScript

In the snippet below, I aim to create a responsive feature based on user input of 'mute' and 'muteon'. Whenever one of these is entered into the textbox, it will change the color of linked elements with the IDs "text" and "text1" to red ...

Establishing session management for tasks in Node.js

I'm currently developing a web application using Node JS and encountering an issue with the session store in req. For my sessions to work, I have set up my app.js like this: // Enable sessions app.use(session({ secret: '***********', ...

The submitEvent.target cannot be converted to formdata in Vue

update I successfully created a new function based on the helpful answer provided below export function getFormDataAsJson(e) { const jsondata = {} let fd= new FormData(e.target) for (let key of fd.entries()) { jsondata[key[0]]=key[1] ...

Updating values of nested objects by ID using Mongoose

As a newcomer to MongoDB, I've been struggling with a simple task that involves changing the status of a process. I've attempted using methods like "FindAndUpdate," "UpdateOne," and "FindByIdAndUpdate," but none seem to be working as expected. ...

Express.js Issue: Error in JSON Object Returned When Date Parameter is Empty

Currently tackling the challenges of the FreeCodeCamp Timestamp Microservice project and facing a roadblock in the implementation. While most requirements are met successfully, there's an issue with handling an empty date parameter test case. Let me b ...

How to create a freeze panes feature like MS Excel using HTML and CSS

In my web application for iPad using Angular JS, HTML5, and CSS3, I'm facing a challenge with a large table that requires both horizontal and vertical scrolling, along with a "freeze-pane" feature similar to MS Excel. Currently, I've divided the ...

The BeanStub initialization failed due to a missing bean reference to frameworkOverrides

I recently updated my ag-grid version to 23.2.0 in my Angular 7 project. Everything was working fine, but when I tried filtering a page and then navigating away, I encountered the following error message: "unable to find bean reference frameworkOverrides ...

Looking to change the date format from 24/05/2021 to 24/May/2021 using jQuery or JavaScript?

My client prefers not to use a date picker, but wants to be able to type dates directly into a textbox and have them automatically converted to the format 24/May/2021 as they leave the field. I am looking for a solution using either Javascript or jQuery. ...

Linking Java objects with Node.js variables

In this snippet of code, I am utilizing the 'java' module in node.js to create Java objects. Specifically, I am creating four Java objects and aiming to consolidate them as a single object by using the variable 'args' to store these Jav ...

Using the React key attribute for components without distinct identifiers

When dealing with a situation where users need to provide a list of timeframes, it can be tricky to generate a unique key for each component in React. Simply using the index of the array is not sufficient, as items can be removed from the middle of the lis ...

Learn how to access the media.navigator.enabled value of Firefox using Javascript

Lately, I've been working on a demo that utilizes getUserMedia() in Javascript to access the webcam of devices and display the video stream on an HTML5 canvas. In cases where browsers do not support getUserMedia(), I have implemented a fallback to a F ...

Angular 2: Encounter with 504 Error (Gateway Timeout)

I am struggling with handling errors in my Angular 2 application. Whenever the backend server is offline, an uncaught error appears in the console: GET http://localhost:4200/api/public/index.php/data 504 (Gateway Timeout) This is how my http.get me ...