简体   繁体   English

带Redux的AG-Grid

[英]AG-Grid with Redux

In my job we decided to use AG-Grid in react variant: https://www.ag-grid.com/best-react-data-grid/index.php 在我的工作中,我们决定使用AG-Grid作为react变量: https : //www.ag-grid.com/best-react-data-grid/index.php

Currently, our architecture for React is Redux . 当前,我们的React体系结构是Redux From my little knowledge of AG-Grid I can say that it doesn't fit very well to this architecture. 根据我对AG-Grid一点了解,我可以说它与该体系结构不太吻合。 AG-Grid keeps it's overall state inside the component. AG-Grid将其整体状态保留在组件内部。 It's cumbersome or even not clever to try to connect it to redux forcefully and completely. 尝试将其强制完全地连接到redux既麻烦又聪明。

I can live with that but at least I need to watch for the row model changes - meaning fetches of new rows, sorts, filtering (I don't need to watch for cell changes). 我可以忍受,但至少我需要注意行模型的更改-意味着获取新行,排序,过滤(我不需要注意单元格的更改)。 I have 2 ideas on how to watch for this and connect it to redux. 我有两个关于如何注意并将其连接到redux的想法。

Option 1 - Use gridOptions.onModelUpdated() 选项1-使用gridOptions.onModelUpdated()

With gridOptions.onModelUpdated() I know when filtering or sort was executed but I can't get to all rows displayed ( docs ): 使用gridOptions.onModelUpdated()我知道何时执行过滤或排序,但无法到达显示的所有行( docs ):

State 1: Row Data 状态1:行数据

API: There is no API to get this data. API:没有API可以获取此数据。 However it was provided by the application so you should already have it. 但是它是由应用程序提供的,因此您应该已经拥有它。

Thus I can't dispatch a redux action as I don't have any data to update it with. 因此,我无法调度redux动作,因为我没有任何数据来更新它。

Option 2 - datasource.getRows() 选项2-datasource.getRows()

I could dispatch actions with new rows. 我可以用新行调度动作。 However, I haven't found any onReset/onRowsDeleted/... event, thus I don't know when to clear redux's state.rows . 但是,我没有发现任何onReset/onRowsDeleted/...事件,因此我不知道何时清除redux的state.rows Update I can know that previous rows were cleared if argumernt params of datasource.getRows(params) is params.startRow === 0 . 更新我可知道,如果argumernt以前行被清除paramsdatasource.getRows(params)params.startRow === 0

Question

Maybe I find a way how to use one of the 2 options but my question is: 也许我找到了一种方法来使用两个选项之一,但是我的问题是:

Are those good ideas to how connect AG-Grid to Redux ? 这些如何将AG-Grid连接到Redux好主意吗?

Ag-grid (v 10.1.0 ) now supports Redux : Ag-grid(v 10.1.0 )现在支持Redux:

https://ag-grid.com/example-react-redux/?framework=all#gsc.tab=0 https://ag-grid.com/example-react-redux/?framework=all#gsc.tab=0

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

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