Skip to content

Deprecated since 7.2

This page documents the classic module layer (CBController and cbInit()). It still works in every 7.x release, but new code should use resources and pages.

Use instead: state(fn ($record) => ...), or withCount() / withSum() in modifyQuery().

How To Make A Subquery Column at Grid Data ​

Table : Products ​

Field NameData Type
idint (PK)
namevarchar(255)
descriptionvarchar(255)

Table : Favorite ​

Field NameData Type
idint(PK)
members_idint(11)
products_idint(11)

Products ​

php
$this->col[] = ["label"=>"Name","name"=>"name"];
$this->col[] = ["label"=>"Description","name"=>"description"];
$this->col[] = ["label"=>"Total Favorite","name"=>"(select count(favorite.id) from favorite where favorite.products_id = products.id) as total_favorite"];

What's Next ​

Table Of Contents ​

Released under the MIT License.