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'; $secondDataProvider->sort->sortParam = 'second-dp-sort';
If we miss these definitions when changing a page or sorting a column, this action will also affect the other GridView in the same page because we have not distinguished...