Yii2 renderAjax Listview

I am trying to render the listview by ajax but it is giving me the following error:


Exception (Invalid Configuration) 'yii\base\InvalidConfigException' with message &#039

;The "dataProvider" property must be set.

Controller:


public function actionLoadListviewAjax()

{

     $dataProvider = // call to a function which returns ArrayDataProvider

     return $this->renderAjax('myview', [ 'dataProvider' => $dataProvider ]);

}

View:


echo ListView::widget([

        'dataProvider' => $dataProvider,

        'itemView'     => 'items',

        'options' => ['class' => 'list-view-post'],

        'summary' => '',

        'emptyText' => '', 

    ]);

$dataProvder:


<pre>yii\data\ArrayDataProvider Object

(

    [key] => 

    [allModels] => Array

        (

            [0] => Array

                (

                    [RecommendationCategory] => 

                    [ID] => 37

                    [GUID] => 

                    [Title] => test

                    [WallPostTypeID] => 1

                    [RecommendationCategoryID] => 0

                    [CommentsJSON] => 

                    [TotalComments] => 

                    [PostedMessage] => test

                    [FirstName] => test

                    [LastName] => test

                    [ProfileImagePath] => Lighthouse.jpg

                    [AddedOn] => 2015-07-18 15:14:06

                    [ImagePath] => 

                    [CommentProfileImagePath] => 

                    [IsSubscribe] => 1

                )


        )


    [id] => 

    [_sort:yii\data\BaseDataProvider:private] => 

    [_pagination:yii\data\BaseDataProvider:private] => 

    [_keys:yii\data\BaseDataProvider:private] => 

    [_models:yii\data\BaseDataProvider:private] => 

    [_totalCount:yii\data\BaseDataProvider:private] => 

    [_events:yii\base\Component:private] => Array

        (

        )


    [_behaviors:yii\base\Component:private] => 

)

I tried renderPartial also but still the same error. Any ideas why it is giving the exeption?

your dataProvider is not a dataProvider. The error says exactly that and it is correct.

A dataProvider is yii\data\ActiveDataProvider object. Your ‘dataProvider’ is yii\data\ArrayDataProvider Object.

So check your code that returns ‘dataProvider’

This is not true. Both yii\data\ActiveDataProvider and yii\data\ArrayDataProvider extend yii\data\BaseDataProvider and are in fact data providers and that is why both are called "DataProvider". Configuration of ListView requires parameter $dataProvider to be object implementing yii\data\DataProviderInterface which is fulfilled by yii\data\BaseDataProvider (so by ActiveDataProvider AND ArrayDataProvider as well).

In this case InvalidConfigException is thrown because $dataProvider is apparently null. Check again if you are setting this param for sure.

ah, thanks for clarification. :)