weixin_39589394
weixin_39589394
2020-12-29 04:25

Multiple datagrids with the same name render the data of the first one

In one window there are shown multiple items from one entity. The entity has attachments so for each item we display the attachment-grid through the view_content_data_additional_information placeholder.

Surprisingly (for me) this kind of works in that for each item there is an attachment grid rendered. The only issue is that the data displayed in all the grids is the data of the first grid.

I investigated this issue and found out that there is a Backbone collection caching system that uses as a key for cache the name of the grid (which for all the grids is attachment-grid).

So for my case I overwrite the datagrid-component.js and compose the cache key with the widget id.

Even though I'm not sure that this is an important issue with the datagrid (because the situation I stumbled upon is rare) I still wanted to notify you of it's existence. If you do agree with me and consider it an issue and decide that you want it resolved I can make a pull request with a fix for it.

The fix I propose is to use the grid id as a key for the cache instead of the grid name or concatenate the grid id to the grid name.

该提问来源于开源项目:oroinc/platform

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

9条回答

  • weixin_39589394 weixin_39589394 4月前

    Here is a visual example:

    Before

    Before

    After

    After

    点赞 评论 复制链接分享
  • weixin_39864453 weixin_39864453 4月前

    Hi, . Thanks for your request. Please make PR, I think this is an interesting issue and if your fix is correct, we can merge it to core code.

    点赞 评论 复制链接分享
  • weixin_39925413 weixin_39925413 4月前

    Hi , I've answered in your pull request. Will oro_datagrid_build_fullname or oro_datagrid_build_inputname twig functions help your issue?

    点赞 评论 复制链接分享
  • weixin_39589394 weixin_39589394 4月前

    No. The attachment widget is rendered in a complicated way and to me it seemed more difficult to pass a unique name rather than disable the caching.

    Long time has passed since then so I don't remember exactly the complication but I know that I could not pass easily a custom grid name. (I just looked a little over the code to refresh my memory and it is not easy to understand how the attachment grid appears: it's coming from a placeholder which outputs a js widget which then renders the grid).

    However I admit that this may not be an issue with the datagrid (and I did say it since I asked if I should do this pull request) but that is why I started this discussion. I don't mind at all if this is not an acceptable solution and this pull request will be rejected.

    While we are having this discussion let me point out that when multiple grids are visible they were not in sync (even though they load from the same cached data). So if I remember correctly when I uploaded a file only one datagrid was refreshing the others were not automatically updating (I hope I'm not mistaken).

    点赞 评论 复制链接分享
  • weixin_39599166 weixin_39599166 4月前

    Please see DataGrid Scope and oro_datagrid_build_fullname helper documentation. It looks like it is best solution for your case.

    点赞 评论 复制链接分享
  • weixin_39779975 weixin_39779975 4月前

    Hi there, in my case using datagrid scope solved the data caching problem, but what I see is that the scope seems to be ignored in the construction of the request on filter update event. So, this solution could not be considered valid for datagrid using filters.

    点赞 评论 复制链接分享
  • weixin_39599166 weixin_39599166 4月前

    Hi

    This is a bug in scope implementation. Thank you for pointing out. We will fix it in coming release.

    点赞 评论 复制链接分享
  • weixin_39779975 weixin_39779975 4月前

    This morning we solved this issue by overriding 'inputValue' option in the renderGrid macro with:

    
    inputName: oro_datagrid_build_inputname(datagrid.name) ~ (datagrid.scope | length > 0 ? ':' ~ datagrid.scope : '')
    
    点赞 评论 复制链接分享
  • weixin_39599166 weixin_39599166 4月前

    The issue is fixed in master branch.

    点赞 评论 复制链接分享

相关推荐