DataProvider for grids

GridView is the widget provided by Yii2 to display data in a grid layout.

This widget requires that data used as an input source is an extension of the abstract class yii\data\BaseDataProvider.

To deal with a data source, DataProvider supplies some additional actions to handle pagination and sorting.

BaseDataProvider has a method named getModels() that returns a list of items for the current page. This means that we could also use DataProvider to paginate data from a source and display it as we need to.

By default, the framework has three core classes that extend yii\data\BaseDataProvider:

  • yii\data\ActiveDataProvider
  • yii\data\ArrayDataProvider
  • yii\data\SqlDataProvider

The first one, ActiveDataProvider, uses a yii\db\Query instance ...

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.