【问题标题】:Sylius Grid, how to sort by property that does not exist in entitySylius Grid,如何按实体中不存在的属性排序
【发布时间】:2021-06-08 13:13:36
【问题描述】:

我有一个使用 Sylius 创建的网格,效果很好。

我的网格中的一个字段是指集合属性(Referees)的计数。

我能够显示此集合的计数(裁判计数),但我无法对其进行排序,因为用于填充网格的实体确实返回集合的任何类型的计数。

代码如下:

grid.yml 中的字段如下所示:

     refereeCount:
       type: twig
       label: 'Referee Count'
       path: 'referees'
       sortable: ~
       options:
         template: AffiliateBundle:admin/referrer:_refereeCount.html.twig

和裁判员Count.html.twig:

{{ data|length }}

我在 Referrer.php 中的 referees 属性用于填充上述网格的实体定义如下:

/**
 * @var Referee[]|Collection
 */
 private $referees;

因此,Gird 正确显示 refereeCount,但我无法对其进行排序。

对于如何按此列的长度进行排序,有人有什么建议吗?

【问题讨论】:

    标签: symfony sylius


    【解决方案1】:

    我通过为我的裁判实体创建一个新的 refereeCount 字段来解决这个问题。我找不到其他解决方法。

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2019-09-19
      相关资源
      最近更新 更多