zii.widgets.grid.CGridView with array of Model items

Hi all, I was looking to the new admin view that use this wonderful layout.

My problem is this, i want to use zii.widgets.grid.CGridView passing to him only an array of items and not a CActiveDataProvider.

I’ll explain better:

I’ve the object $category. Category has a relation with post. So in $category->posts i’ve all the posts related to the category.

How can I do like in the admin view without using CActiveDataParameter? Someone can give me a code example?

Thank you very much :)

How do you plan to do sorting and pagination then?

You could try directly setting $dataProvider->data=$items. There may still be problems if you want sorting and pagination.

The problem is that I don’t want to do another query when I already taked from db have the items i needed.

Can’t I create only a CActiveDataProvider with the pagination and so without the criteria parameter and then assign to the CActiveDataProvider object the items with setData? When i will use the pagination widget will perform a new query or just filter the object that the ActiveDataProvider store?

There is extension arraydataprovider - you can use it to solve your task. And I am attaching modified version with pagination support - 441


You can use it like this:

$dataProvider = new CArrayDataProvider(

    'Post', $category->posts,



                'pageSize' => 20




cool thanks :)

everything works, the problem is that with your extension you can’t click on the column name to order the items on it.

I need this help too… anyone have the solution which include sorting?