Multiple grids on one page
Every Yii2 widget has so much encapsulated in it that using multiple GridView widgets is a simple activity that involves making few changes.
The only parameters indeed that are not customizable with the DataProvider model class are pageParam
and sortParam
, which define the current page index and the parameters used to order a grid.
Suppose, for example, that we have two GridViews filled with two different data providers, $firstDataProvider
and $secondDataProvider
.
In the controller, we will set the pageParam
and sortParam
parameters of each DataProvider:
$firstDataProvider->pagination->pageParam = 'first-dp-page'; $firstDataProvider->sort->sortParam = 'first-dp-sort'; $secondDataProvider->pagination->pageParam = 'second-dp-page'; ...
Get Yii2 By Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.