Updating and saving data in Ag-Grid with server communication

Is it possible to create a grid using Ag-Grid on Angular that fetches data from a local JSON file? And how can the edited row data be saved and sent to the server or back to the local JSON file?

In summary, I would like to know how to save edited row data in Ag-Grid and send it to the server upon clicking the Submit button. If anyone has successfully implemented this functionality using JavaScript, please share your insights as I am looking to incorporate it into an Angular project.

If there are any alternative solutions besides using Ag-Grid for achieving this specific feature, I'd appreciate hearing about them as well.

Answer №1

To monitor specific changes in a particular row, you can utilize the onCellValueChanged or onRowValueChanged event bindings when setting up the ag-grid component in your component template.

 <ag-grid-angular 
.
.
(gridReady)="onGridReady($event)"
(onRowValueChanged) = onRowValueChanged($event)
>

In your component.ts file, the onRowValueChanged method will trigger every time a change is made to the data.

 export class YourComponent {
 private gridApi;
 private gridColumnApi;
   .
   . 
 onRowValueChanged: function(event) {
   console.log(event) // access the entire event object
   console.log(event.data) // view and print the updated row data
   const gridData = this.getAllData();
   // make an api call to save the data

}

getAllData() {
  let rowData = [];
  this.gridApi.forEachNode(node => rowData.push(node.data));
  return rowData;  
}

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

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 launching myapp on the Android Studio emulator for Ionic 3

My current project involves using Ionic with Cordova to develop an app without any visible errors in the CLI. I am also utilizing Android Studio to emulate the app. In addition, I am relying on the Chrome inspect feature to monitor my app's behavior ...

Using a click event to target the next div and apply a CSS class using Typescript

I am trying to create a Typescript function that will locate the next div and apply a CSS class to it. Here is what I have attempted: <ul> <li><a href="#" onclick="toggle()">Item 1</a></li> <div class="content hide ...

lines stay unbroken in angular

I am encountering an issue when I execute the following code: DetailDisplayer(row) : String { let resultAsString = ""; console.log(row.metadata.questions.length); (row.metadata.questions.length != 0 )?resultAsString += "Questions ...

Activating the Play button to start streaming a link

Recently delved into the world of Ionic 4 and Angular, so definitely a beginner :) Purchased a UI Template from code canyon but didn't realize I needed to code the music player part. Been trying to get a music stream playing but no luck. Came across ...

What could be the reason for the ERROR message saying, "Cannot read property '0' of undefined"?

I'm really struggling to understand why I keep receiving an Undefined error for tagged_Assets. Can someone please shed some light on this for me? Thank you. Model.ts export class TaggedAssests { device_id: string; hasTag: boolean; } Compon ...

Encountering TypeScript error TS2345 while attempting to reject a Promise with an error

I recently encountered a perplexing TypeScript error message that I am struggling to comprehend. The specific error reads as follows: error TS2345: Argument of type '(error: Error) => void | Promise' is not assignable to parameter of type & ...

Is it feasible to pre-render an Angular2 view invisibly when hovering?

Can a view be preloaded and prerendered invisibly upon hover? I have an application that displays a list of items. Each item is its own component, and when you click on any of these items, it is replaced by a detailed view (another component) of the same ...

Error 404 occurs when attempting to retrieve a JSON file using Angular's HTTP

I'm having an issue with my service code. Here is the code snippet: import {Injectable} from '@angular/core'; import {Http, Headers, RequestOptions} from '@angular/http'; import 'rxjs/add/operator/map'; import {Client} f ...

What is the best way to retrieve the instance of a different component?

This question is not specifically referring to a child component, and therefore using ViewChild is not an option. The query here is if it's feasible to inject any component into another component. There was a related discussion on Stack Overflow, but ...

Using Material UI date picker with TypeScript: A Complete Guide

Well, I have to admit that I usually don't resort to putting 'any' as the type when I'm uncertain what to do, but right now, I'm starting to feel quite frustrated. I'm currently working with Material UI date picker in conjunct ...

Issue: Module compilation unsuccessful (from ./node_modules/css-loader/dist/cjs.js) during upgrade from Angular 11 to Angular 16

Summary: Can anyone help with a strange error I encountered while updating my Angular application? Situation: After finally updating my Angular 11 app to Angular 16, I faced several fixable errors along the way. However, one particular error is now hind ...

Generate an instance containing attributes that correspond to constant string values within a class

In the world of TypeScript, I have a scenario that might be a bit tricky, but I'll throw it out there anyway. Let's say I start with a base service class: export default class Service { public static readonly accessorName: string constructo ...

When attempting to asynchronously observe a datasource, the 'number' type cannot be assigned to the 'NgIterable<any>' type

I'm currently working with this simplistic component: import { Component, VERSION } from '@angular/core'; import { Observable, Observer } from 'rxjs'; @Component({ selector: 'my-app', templateUrl: './app.compone ...

When attempting to assign a 'string' type to the @Input property, I am receiving an error stating that it is not assignable to the 'PostCard Layout' type

Encountering an issue The error message 'Type 'string' is not assignable to type 'PostCard Layout'' is being displayed A parent component named page-blog.component.html is responsible for defining the class styles and passi ...

Developing maintenance logic in Angular to control subsequent API requests

In our Angular 9 application, we have various components, some of which have parent-child relationships while others are independent. We begin by making an initial API call that returns a true or false flag value. Depending on this value, we decide whether ...

Query parameters in Angular 5 that have a global scope

Adding a global query parameter to every path of the application is my goal (such as /my/path?config=foo). I prefer not to use the option to preserve query params because I only want to retain this specific one. The application operates with various confi ...

Missing data list entries for next js server actions

After successfully running my add function, I noticed that the data I added earlier is not being reflected in the list when I check. import React, { useEffect, useState } from "react"; import { createPost } from "./actions"; import { SubmitButton } from ". ...

Solve the issue of the __typename union

Imagine having the following union: export type IBookmarkItemFragment = | ({ __typename: "Story" } & { story: number; }) | ({ __typename: "Product" } & { product: number; }) | ({ __typename: "Project" } & { proj ...

Tips for displaying both the time and date using Angular Material Date Picker

I recently integrated the Angular Material date picker control into my Angular project. I want to display both the date and time together. Could someone please advise me on how I can achieve this using the Angular Material date picker control? Appreciate ...

Ways to customize the placeholder for Material input fields in Angular 5

Is it possible to customize the placeholder color in an Angular Material input field? <mat-form-field> <input matInput placeholder="Name"> </mat-form-field> ...