Yii 1.1:Loading data in Yii Grid View on fly using API

Can anyone tell me how to load data using API in Grid View in Yii1.1?

This should happen dynamically as the values coming from API can’t be stored in a database.

I tried this :

$dataProvider = new ArrayDataProvider([
  
    'allModels' => Url::to(['userlocations/get-location-address']),
    // Might need this too... (assuming number is unique identifier)
    'key' => 'number',
    // Setup sorting if not using default
    'sort' => [
        'attributes' => ['number', 'name'],
    ],
    // Set pagination if not using default
    'pagination' => [
        'pageSize' => 10,
    ],
]);

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'number',
        'name',
    ],
]);

I think you have to implement these methods:

  • CDataProvider is a base class that implements the {@link IDataProvider} interface.
  • Derived classes mainly need to implement three methods: {@link fetchData},
  • {@link fetchKeys} and {@link calculateTotalItemCount}.

https://www.yiiframework.com/doc/api/1.1/CDataProvider#getData-detail