O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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'; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required