tareq
tareq

Reputation: 1129

Using yii2's gridview with a normal array of data

I have an array of data very similar to this

[
    'name'=>'mark',
    'age'=> '21'
    'height'=> '190 cm'
]

I searched Google and all the results i found were using an active record object.

How do i use the gridview with an array of this sort?

Upvotes: 11

Views: 13283

Answers (1)

zelenin
zelenin

Reputation: 804

You should use ArrayDataProvider (https://github.com/yiisoft/yii2/blob/master/framework/data/ArrayDataProvider.php)

$provider = new ArrayDataProvider([
    'allModels' => $yourArray,
    'sort' => [
        'attributes' => ['id', 'username', 'email'],
    ],
    'pagination' => [
        'pageSize' => 10,
    ],
]);

Upvotes: 20

Related Questions