简体   繁体   English

我如何删除 Ag-grid 中的空行反应

[英]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.我在我的项目中使用 ag-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.在保存之前,我通过将 gridApi 传递给该方法来执行一些验证,并且 gridApi.foreEachNode 我正在验证数据。 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?如何删除 forEachNode 中的行节点?

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.我建议在迭代 forEachNode 时为空行构建一个行 ID 数组,然后在完成迭代后,使用数组中的 ID 删除行。

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.相反,在您的应用程序中保留一个数据 model,并将网格用作一个可视组件(尽管是一个复杂的组件),它表示 model 中的数据。

React is particularly suited for this, as you can use, eg Redux to represent your model and provide operations on it. React 特别适用于此,因为您可以使用例如 Redux 来表示您的 model 并提供对它的操作。

In this scenario, you would do these operations on your model, and then update the grid with the new value of your model.在这种情况下,您将在 model 上执行这些操作,然后使用 model 的新值更新网格。 And your model would then be in a good state to send to your back-end.然后您的 model 将在一个好的 state 中发送到您的后端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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