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\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

<?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});});
$.pjax.reload('#datalist'); });
<?php $this->endBlock(); ?> <?php $this->registerJs($this->blocks['pagejs'], \yii\web\View::POS_END); //將編寫的js代碼註冊到頁面底部 ?>
相關文章
相關標籤/搜索