After a cell editing event, there are times when the grid data is not saved properly due to

I have integrated the ag-grid library into my project for data display. After editing a cell, I want to save the changes to the backend database by persisting the rowData. Most of the time, this process works smoothly, but occasionally I encounter an issue where an empty array gets serialized and persisted, for reasons unknown to me.

Currently, I am utilizing the onCellEditingStopped event to trigger the saving operation. Below is a snippet of code from my component:

this.plansGridOptions.onCellEditingStopped = this.cellEditingStopped;

cellEditingStopped(params: CellEditingStoppedEvent) { 

    let context = <ImportSessionComponent>params.context;
    context.saveSession().subscribe(r => { });

}

saveSession(): Observable<any> {
    //The row data array is serialized and saved
    //However, sometimes plansRowData turns out to be empty here.
    this.importForm.get("uploadItemsSerialized").setValue(JSON.stringify(this.plansRowData));
    return this.importService.saveSession(this.importForm);
}


saveSession(sessionForm: FormGroup): Observable<any> {
    //Converting strings to numbers for proper viewmodel binding in the backend
    const value = {
        ...sessionForm.value, importType: +sessionForm.get("importType").value, environment: 
        +sessionForm.get("environment").value,
        id: +sessionForm.get("id").value, version: +sessionForm.get("version").value, stepIndex: 
        sessionForm.get("currentStep").value
    };
    return this.http.post<any>("/import/save", value);
}

Below is the template markup for the grid:

<ag-grid-angular #planGrid style="width: 100%; height: 475px;"
    class="ag-theme-balham-dark"
    [rowData]="plansRowData"
    [gridOptions]="plansGridOptions"
    [columnDefs]="plansRowConfig">
</ag-grid-angular>

It appears that the synchronization between the grid component and the array in my component is not always consistent (i.e., the event I'm using is fired before the plansRowData array is updated). Should I consider using a different event to trigger the save functionality? What might be causing this inconsistency?

Answer №1

Perhaps considering a switch to the cellValueChanged event could be beneficial? This approach seems logical as it is intended to trigger after a value has been changed, eliminating any potential issues with data not being updated prior to handling it. It may be more appropriate than using the onCellEditingStopped event (uncertain about the specific order of lifecycle hooks).

I am aware that AG Grid employs interesting timing mechanisms - there have been instances where I had to utilize setTimeout in certain places to ensure proper functionality, particularly for resizing operations.

API reference.

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 steps do I need to take to create a pristine build of the Microsoft/VSCode source code?

Currently working on setting up a fresh development environment for microsoft/vscode. As a beginner in JS, TS, NPM, and Yarn, which specific command should I run in order to delete all build artifacts and output files and compile the code changes I made? ...

What is the best way to remove linear-gradient effects applied by a dark mode theme?

Why does MUI add random gradients to components, like in dark mode? Is there a way to disable this feature because it doesn't match the exact color I expected for my custom theme... My Theme Options export const themeOptions: ThemeOptions = { palette ...

Make TextField with type number forcibly show dot as decimal separator

I am currently utilizing the material-ui library to display a TextField component in my react application. Strangely, all instances of <TextField type="number /> are displaying decimal separators as commas (,) instead of dots (.), causing confusion f ...

Track and log async routes for undefined values once await is complete

Currently facing challenges with multiple queries and synchronous code while writing an Express endpoint in TypeScript to update a user's password in the database. The issue I am encountering is that when attempting to await the return of a function, ...

Issues with Angular not reflecting data changes in the view after updates have occurred

I have a setup with two components. One is responsible for creating new data entries, while the other one is in charge of listing all the data stored in a database. The issue I'm facing is that even though the creation component successfully adds new ...

Angular unit testing using Jasmin Karma encountered an error stating: "Unable to locate the name 'google'."

codeSnippet.js:- getAutocompleteResults(inputElement: ElementRef) { const autocomplete = new google.maps.places.Autocomplete(inputElement.nativeElement, { ... }); google.maps.event.addListener(autocomplete, 'place_changed&a ...

Maximizing Performance of JSON.stringify in Angular

In my Angular app, I have a service that retrieves JSON data from an API. At times, this API sends back over 400 records (JSON Objects). When I directly access the endpoint in my browser, it takes around 5 seconds to load all the JSON data onto the page. ...

Can TypeScript support passing named rest arguments within the type declaration?

Using Tuple types in TypeScript enables us to create typesafe rest arguments: type Params = [string,number,string] const fn = (...args: Params) => null // Type is (args_0: string, args_1: number, args_2: string) => null Is there a method to assign ...

I'm facing some difficulties in sourcing my header into a component and encountering errors. Can anyone advise me on how to properly outsource my header?

Looking to streamline my headers in my Ionic 4 project by creating a separate reusable component for them. Here's how I set up my dashboard page with the header component: <ion-header> <app-header title="Dashboard"></app-he ...

What is the best way to implement pipes and incorporate reusable action buttons in a Mat-table component for maximum reusability?

I am seeking assistance in creating a reusable component for the Angular Material Mat-table. I have made progress on loading data from the parent component to the child component, as can be seen in StackBlitz, but I now want to apply pipes to the data bef ...

Issue deploying Angular 2 and Rails 5 on Heroku: npm command not found in bash

After successfully deploying an Angular2 on Rails5 app to Heroku and setting up the PG database, I encountered a stack trace in the Heroku app log indicating that the npm command was not found. This error has been perplexing as I try to troubleshoot the is ...

When HTMLElement focus is activated, it interrupts the flow of execution

(the code presented is in TypeScript and I'm working with Angular 5, but I don't think that's the issue, so prove me wrong!) I have a basic input field that triggers events in an Angular component. (EDIT: I've added the complete compo ...

When should you utilize the Safe Navigation Operator (?.) and when is it best to use the Logical AND (&&) operator in order to prevent null/undefined references?

Imagine having an object property (let's call it arrThatCouldBeNullOrUndefined: SomeObjType) in your Angular component. You aim to perform an array operation (let's say filter() operation) on its data: DataType[] object and save the result in an ...

Implementing queuing functionality in Angular's HttpClient

I am facing a similar requirement that was discussed in Add queueing to angulars $http service, but I am looking for an implementation in Angular 4.3 or 5 using the HttpInterceptor from @angular/common/http. The API I am working with has some unique limit ...

Why is ASP.NET Core returning an empty object in the response?

Upon debugging the code in VS, I noticed that the cities list I am returning contains 3 objects with properties. However, when I call the endpoint, I receive a response of 3 empty list items. How can I resolve this issue? Model Class: public class City ...

A guide on leveraging the modal window function within Angular

I have a simple list of files with a "Delete" button. I have added a modal window for confirmation, but I am unsure how to connect the Delete function from the main component to the modal window. The modal window is implemented using the @angular/materia ...

Error in Typescript: Function expects two different types as parameters, but one of the types does not have the specified property

There's a function in my code that accepts two types as parameters. handleDragging(e: CustomEvent<SelectionHandleDragEventType | GridHandleDragEventType>) { e.stopPropagation(); const newValue = this.computeValuesFromPosition(e.detail.x ...

Prevent Promise / Property not found error in Angular2 by Instantiating Class

When working with my "export class", I encountered an issue that led to a Promise error if I didn't include this line of code: purchase = new Purchase(); right before the constructor. The error indicated that the property "name" was not found. Alth ...

I'm attempting to integrate Angular Material into my project but I'm struggling to figure out how to resolve the issue

npm ERR! code ERESOLVE npm ERR! ERESOLVE was unable to find a resolution npm ERR! While resolving: [email protected] npm ERR! Found: [email protected] npm ERR! node_modules/tslint npm ERR! dev tslint@"~6.1.0" from the root projec ...

Separate string by using a regular expression pattern

Looking to parse a dynamic string with varying combinations of Code, Name, and EffectDate. It could be in the format below with all three properties or just pairs like Code-Name, Code-EffectDate, or Name-EffectDate. {"Code":{"value":"1"},"Name":{"value": ...