ds122455 2017-02-01 03: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 03: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 求Houdini使用行家,付费。价格面议。
  • ¥15 AttributeError: 'EasyDict' object has no attribute 'BACKUP_DB_INFO'
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 CF1927D 求Hack