Answer the question
In order to leave comments, you need to log in
How can I reload the page with the output of the number of records per page?
I don't know what to do right. There is a page where the number of records is displayed and dropdown where it is indicated how much to show the number of records.
I tried to do something like this
<?php Pjax::begin([
'id' => 'pjax-rows'
]) ?>
<div>
<?php foreach ($model as $posts): ?>
<div><?= Html::img('/'.$posts->image_path) ?></div>
<h3><?= $posts->title ?></h3>
<div><?= $posts->description ?></div>
<div><?= Html::a('Подробнее', \yii\helpers\Url::to(['site/post', 'id' => $posts->id])) ?></div>
<hr/>
<?php endforeach; ?>
</div>
<div><?= Html::dropDownList('countRow', null, [
10 => 'Показат 10 страниц',
25 => 'Показат 25 страниц',
50 => 'Показат 50 страниц'
], [
'class' => 'count-rows',
'data-url' => \yii\helpers\Url::to(['site/index'])
]) ?>
</div>
<?php Pjax::end() ?>
<?php
$script = <<<JS
$('.count-rows').click(function() {
let select = $(this);
location.reload(select.data('url') + '&countRow=' + select.val());
})
JS;
$this->registerJs($script);
?>
public function actionIndex()
{
$query = News::find()->with('user')->where(['status' => News::NEWS_ACTIVE]);
$request = Yii::$app->request->get('countRow');
$count = $request ? $request : 1;
$pages = new Pagination(['totalCount' => $query->count(), 'pageSize' => $count]);
$posts = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('index', [
'model' => $posts,
'pages' => $pages
]);
}
Answer the question
In order to leave comments, you need to log in
pjax has a standard method for reloading the contents of a container.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question