Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using yii2's gridview with a normal array of data

Tags:

php

yii2

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?

like image 746
tareq Avatar asked Jul 20 '14 08:07

tareq


1 Answers

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,
    ],
]);
like image 171
zelenin Avatar answered Sep 24 '22 10:09

zelenin