简体   繁体   English

ag-grid:使用“ serverSide” rowModel刷新当前视图

[英]ag-grid: Refresh current view with 'serverSide' rowModel

Very simple question, with a seemingly impossible to find answer: 一个非常简单的问题,似乎无法找到答案:

When using gridOptions:{ rowModel: 'serverside'} data is loaded through the getRows callback. 使用gridOptions:{ rowModel: 'serverside'}数据将通过getRows回调加载。

But how can we simply "refresh" the grid, so that it executes the last getRows call again and updates the data in place? 但是,我们如何简单地“刷新”网格,以使其再次执行最后的getRows调用并更新数据呢?

Right now it seems absolutely impossible to do this without calling gridApi.purgeServerSideCache() , however this results in the collapse of all opened row groups which I'd like to avoid for obvious UX reasons. 现在,如果不调用gridApi.purgeServerSideCache()似乎绝对不可能这样做,但是这会导致所有打开的行组崩溃,出于明显的UX原因,我希望避免这些行组崩溃。

This link to ag-grid documentation should be helpful: https://www.ag-grid.com/javascript-grid-server-side-model-grouping/#preserving-group-state 此指向ag-grid文档的链接应该会有所帮助: https : //www.ag-grid.com/javascript-grid-server-side-model-grouping/#preserving-group-state

Essentially, the docs state that using gridApi.purgeServerSideCache() is the preferred way to force a reload, but they go on to say the following which should solve the UX concerns you have: 本质上,文档指出使用gridApi.purgeServerSideCache()是强制重新加载的首选方法,但是他们继续说以下内容应该可以解决您遇到的UX问题:

Preserving Group State 保留组状态

It may be necessary to expand groups to a desired initial state or to restore the grid to a previous state after purging / reloading data. 在清除/重新加载数据后,可能有必要将组扩展到所需的初始状态或将网格恢复到先前的状态。

This can be achieved by expanding row nodes as blocks are loaded in the Server-side Datasource. 这可以通过在将块加载到服务器端数据源中时扩展行节点来实现。 The following snippet outlines a possible approach: 以下代码片段概述了一种可能的方法:

 function getRows(params) {
>     // 1) get data from server
>     var response = getServerResponse(params.request);
> 
>     // 2) call the success callback
>     params.successCallback(response.rowsThisBlock, response.lastRow);
> 
>     // 3) to preserve group state we expand any previously expanded groups for this block
>     rowsInThisBlock.forEach(row => {
>         if (expandedGroupIds.indexOf(row.id) > -1) {
>             gridOptions.api.getRowNode(row.id).setExpanded(true);
>         }
>     }); 
>  }

Notice that in step 3, newly loaded row nodes for the current block are expanded if they are defined in expandedGroupIds, which is an array of group keys maintained by the application. 请注意,在第3步中,如果当前块的新加载的行节点是在expandedGroupIds中定义的,则该行节点是由应用程序维护的一组组键的数组。 This will have a cascading effect as expanding a group will cause new block(s) to load. 这将具有级联效果,因为扩展组会导致加载新块。

In order to easily look up group row nodes, implementing the following callback is recommended: gridOptions.getRowNodeId(). 为了轻松查找组行节点,建议实现以下回调:gridOptions.getRowNodeId()。

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

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