0

i have an api call the client side like

function doInBackground(){
       $.get('car/get-map-data',
          {
           'params':'$params'
      },
      function(data){
        if(data)
        {
          console.log(data);
        }
      }); 
    }

$params is the search Params. And my server code is like

public function actionGetMapData($params){
        $searchModel=new CarSearch();
        $dataProvider=$searchModel->search($params);
        $models=$dataProvider->getModels();
        $mapData=array();
        foreach ($models as $key => $model) {
            array_push($mapData, $model->title);
        }
         return json_encode($mapData);
     }

I have a page size of 10 in the search

$query = Car::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

And here is my response of first call means first page of pagination

["Dodge Challenger | 2012 | GCC | Very Good Condition | Free Accidents","RALLYE \/ V4 \/ 2.4L \/\/\/ FULL OPTION \/\/\/ NEGOTIABLE","2015 FERRARI CALIFORNIA T CONVERTIBLE GCC SPECS IN PERFECT CONDITION UNDER SERVICE CONTRACT","V8\/HEMI\/5.7L \/\/\/ NEGOTIABLE \/\/\/ SRT KIT\/Monthly 825\/-","Ferrari F430 Scuderia","GCC \/ SRT \/ 6.4L\/ Agency maintained","Ford Focus","Dodge Charger \/ SXT \/ 3.6 LT \/ V6 \/","STUNNING FERRARI CALIFORNIA T \/\/ 2013 \/\/ GCC \/\/ FULL SERVICE HISTORY !!!","Ford Fiesta 2012, full service history, al tayer, big service already done"]

Now i am getting first 10 datas from the server.Now i want to iterate the same to get the all data page by page.How to do that iteration

Abhi Jith
  • 17
  • 4
  • What is the response data from your server? – Shantanu Apr 04 '20 at 07:37
  • @shantanu response added to the question.The response contains the titles array – Abhi Jith Apr 04 '20 at 07:44
  • You need to modify your yii code to accept page numberin request and pass the same in your pagination value https://www.yiiframework.com/doc/api/2.0/yii-data-pagination – Shantanu Apr 04 '20 at 07:48
  • Pagination is done by [`OFFSET, LIMIT`](https://stackoverflow.com/questions/3705318/simple-php-pagination-script) clauses on the database` **IF AND ONLY IF** your data set is not big , if your data size is big, you should go with the [`PK > x , LIMIT` solution](http://mysql.rjweb.org/doc.php/pagination) – Accountant م Apr 04 '20 at 07:51

0 Answers0