ds122455 2017-02-01 11:37
浏览 289
已采纳

仅在yii2中重新加载gridview

How can I, reload only grid-view on on change event of drop-down in Yii2?

I know that it can be done via pjax but not sure where and how to use the code.

I am using Ajax request for communicating with controller. Here is the ajax code:-

function loadGrid(level) { 
    alert(level); 
    $.ajax({ 
        type: 'GET', 
        url: 'index.php?r=villagedata/level', 
        data: {level:level}, 
        success: function(data) 
        { 
            alert("Success"); 
            $.pjax({container: '#myview'}); 
        } 
    }); 
} 

I wan't my grid to reload when the Ajax Request returns success message.

Thank You.

  • 写回答

2条回答 默认 最新

  • dpswo40440 2017-02-01 11:58
    关注

    Exactly, using Pjax.

    use yii\grid\GridView;
    use yii\widgets\Pjax;
    
    <?php Pjax::begin(['id' => 'pjax-grid-view']); ?>    
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'columns' => [
                '...'
            ],
        ]); ?>
    <?php Pjax::end(); ?>
    

    and jQuery to detect drop down change.

    If dropdown has "dropdown" id,

    $('#dropdown').on('change', function(ev) {
         $.pjax({container: '#pjax-grid-view'})
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 静电纺丝煅烧后如何得到柔性纤维
  • ¥15 (标签-react native|关键词-镜像源)
  • ¥100 照片生成3D人脸视频
  • ¥15 伪装视频时长问题修改MP4的时长问题,
  • ¥15 JETSON NANO
  • ¥15 VS开发qt时如何在paintgl函数中用pushbutton控制切换纹理
  • ¥20 关于 openpyxl 处理excel文件地问题
  • ¥15 MS中不知道高分子的构型怎么构建模型
  • ¥60 QQOP数据,什么是op数据号,怎么提取op数据!能不能大量提取(语言-c语言)
  • ¥15 matlab代码 关于微分方程和嵌套的分段函数。