简体   繁体   中英

How can i delete empty row in Ag-grid react

I am using ag-grid enterprise in my project where i am inserting data into the grid. Once the editing of data is completed i am pressing submit button to save the entries in the backend. Before saving there are some validations which i am performing by passing gridApi to the method and there gridApi.foreEachNode i am validating the data. I have a new scenario where if all the cells of the row is empty. The row should be deleted so that user should not have to delete every empty row before submitting. how can i delete the row node inside foreEachNode?

I recommend that build up an array of row ids for the empty rows as you iterate through forEachNode, and then once you are done iterating, use the ids from the array to delete the rows.

However, I'd like to recommend an entirely different approach... That is, don't treat the grid as the "source of truth" for your data.

Rather, keep a data model in your application, and use the grid just as a visual component (though a complex one), that represents the data in your model.

React is particularly suited for this, as you can use, eg Redux to represent your model and provide operations on it.

In this scenario, you would do these operations on your model, and then update the grid with the new value of your model. And your model would then be in a good state to send to your back-end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM