Answer the question
In order to leave comments, you need to log in
Ajax loading in GridView Yii2?
Good afternoon. In a Yii2 project, Gridview is used to display data.
Actually the question is: how in Yii2 to make it so that instead of pagination, the data was loaded into the table when scrolling?
Prompt the decision or kick in the necessary direction.
Google gives the wrong thing :( Thanks in advance.
Answer the question
In order to leave comments, you need to log in
GridView has nothing to do with it, it just builds a table based on the data you feed it, and you feed it data in an ActiveDataProvider that has a pagination that contains the yii\data\Pagination object. It contains data on the current number of records, so we just wrap everything in pjax and write js that will scroll up to a certain point, launch pjax already at a new url, with a new limit.
There is a ready-made solution, I have not tried it, but there are a lot of stars, so it should work:
https://github.com/kop/yii2-scroll-pager
Google does not give you results, because you are looking for gridView , but it has nothing to do with this task , look for "yii2 scroll pager" or something similar
Google "pjax".
How to use it when clicking on a pagination - for example, https://habrahabr.ru/post/225823/
For autoloading when scrolling, you will have to emulate a click on the desired pagination when scrolling.
I have your example with only the "Show more" button. Tweak my code for you
1) Hide the pagination
2) This is under the GridView
<?php
echo Html::a('Показать ещё', [Url::to('').'#ddd'], [
class' => 'btn btn-default',
'data' => [
'method' => 'post',
'params' => [
'more' => $more,
],
'pjax' => 1,
],
'id' => 'ddd',
]);
?>
if($more = (int)Yii::$app->request->post()['more']){
$dataProvider->pagination->pageSize += $more;
}
return $this->render('index',[
/**/
'more' => $more > 0 ? $more + 10 : 10,
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question