If you are worried about too many queries, I would suggest you change your [font="Courier New"]dataProvider[/font] itself (either use a DB View or a join query as source for your dataProvider and the search model).
Not quite. This executes n number of queries, where n = number of results in the grid search.
To optimize this, you’ll need to eager load the related data in the search model.
$query = $model::find();
$query->with("a"); // eager load data
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
This will result in 2 queries:
select * from b
select * from a where a_id in (1,2,3,etc)
There have actually been several topics on GridView, so I wrote a tutorial on processing related model data. If you want to go further with sorting and filtering, check it out here.