Is there an option for this to enable me to pass to it, only the amount of items I wish to display, and pass it a total count value for it to calculate the pagination.
So that for instance, I set pagination to 15, and total to 600. It would provide the pagination for all those pages, but would be given 15 results at a time. As opposed to being given all 600 and it only display the amount it needs.
I am using a restful api on another server which handles getting the paged data, I just need to send it the page and offset, which I can get from the yii pagination as it uses get parameters.
Regards
Just trying to logically sequence your problem to reach to the solution:
- To create a ActiveDataProvider you usually start with a yii query object. Something like:
$query = Customer::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
- You wish to set a limit to the number of records returned by dataProvider (let’s say 600) - so you change it to this:
$query = Customer::find();
$query->limit(600);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
- You wish to also pass in the pagesize (say 15 rows/page) - change your dataProvider to this
$query = Customer::find();
$query->limit(600);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => ['pagesize' => 15]
]);
Thanks Kartik, not quite what i was after but ive managed to solve my issue.
This is what i did:
$model = new RestSupplier();
if(Yii::$app->request->get('page') !== null)
{
$page = Yii::$app->request->get('page');
$perpage = Yii::$app->request->get('per-page');
}else
{
$page = 1;
$perpage = 10;
}
$array = $model->getAll($page,$perpage);
$count = $model->getcount();
$pages = new Pagination(['totalCount' => $count,'forcePageParam' => true, 'pageSize' => 10]);
$provider = new ArrayDataProvider([
'allModels' => $array,
'pagination' => false,
]);
return $this->render('form', [
'provider' => $provider,
'pages' => $pages,
]);
Is there a way to hide the index? which the pagination adds to the url?
Ah… your topic mentioned ActiveDataProvider… … but see that you are using ArrayDataProvider… anyway good you got it resolved .
You are correct that was my mistake, I thought I was using Active but after reviewing and revising I am using Array
Many Thanks