yii2 pjax使用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了yii2 pjax使用相关的知识,希望对你有一定的参考价值。
Pjax::begin([‘id‘=>‘datalist‘]); echo GridView::widget([ ‘dataProvider‘ => $dataProvider, ‘columns‘ => [ [‘class‘ => yii\grid\CheckboxColumn::className()], ‘id‘, [ ‘header‘ => ‘姓名‘, ‘label‘ => ‘姓名‘, ‘attribute‘ => ‘name‘ ], [ ‘header‘ => ‘职位‘, ‘label‘ => ‘职位‘, ‘attribute‘ => ‘position‘ ], [ ‘header‘ => ‘手机‘, ‘label‘ => ‘手机‘, ‘attribute‘ => ‘mobile‘ ], [ ‘header‘ => ‘状态‘, ‘label‘ => ‘状态‘, ‘attribute‘ => ‘status‘, ‘value‘ => function($data) { return app\models\intro_user::getStatus()[$data->status]; } ], [ ‘header‘ => ‘操作‘, ‘class‘ => ‘yii\grid\ActionColumn‘, ], ], ‘layout‘ => "{items}\n{summary}\n<div style=\"text-align:center;\">{pager}</div>", ‘summary‘ => false, //‘summaryOptions‘=>[‘class‘ => ‘summary‘], ]); Pjax::end();
其他的一些链接需要使用pjax时这么用(不能使用js的跳转,支持a标签,和form):
<?php $this->beginBlock(‘pagejs‘); ?> $(function () { /*search start*/ $(‘.usico-search‘).on(‘click‘, function () { var name = $.trim($(‘.search‘).val()); if (name) { //window.location.href = ‘<?= Url::to([‘/oamanager‘]) ?>?name=‘ + name; } else { $(‘.search‘).focus(); return false; } }); /*search end*/ jQuery(document).pjax("button a[link-pjax]", "#datalist", {"push":true,"replace":false,"timeout":1000,"scrollTo":false}); jQuery(document).on(‘submit‘, "form[data-pjax]", function (event) {jQuery.pjax.submit(event, ‘#datalist‘, {"push":true,"replace":false,"timeout":1000,"scrollTo":false});}); }); <?php $this->endBlock(); ?> <?php $this->registerJs($this->blocks[‘pagejs‘], \yii\web\View::POS_END); //将编写的js代码注册到页面底部 ?>
以上是关于yii2 pjax使用的主要内容,如果未能解决你的问题,请参考以下文章