Reputation: 1
My array
$data = [
'subcategoryName' => 'asd',
'fromdate' => $fromdate,
'todate' => $todate,
'amount' => $finalamount,
];
Array data provider
$provider = new ArrayDataProvider([
'allModels' => $data,
'pagination' => [
'pageSize' => 10,
],
'sort' => [
'attributes' => ['subcategoryName'],
],
]);
// get the rows in the currently requested page
$rows = $provider->getModels();
return $rows;
Now I want to display this data on my grid view but I am getting this error Call to a member function getCount() on array
Please tell me that how can I display my array on yii2 grid view
Upvotes: 0
Views: 798
Reputation: 5032
You should'nt return here result of function getModels()
. I assume u pass this to GridView
, but u have to pass ArrayDataProvider
.
Change this:
$rows = $provider->getModels();
return $rows;
To this:
return $provider;
Upvotes: 2