2016-09-18 3 views
3

전체 페이지를 새로 고치지 않고 pjax listview를 새로 고칠 수 있기를 원합니다. 이것은 pjax 목록 자체의보기입니다.yii2에서 pjax listview를 새로 고치는 방법은 무엇입니까? 전체 페이지를 다시로드합니다.

<?= Html::Button('refresh-countries', ['class' => 'btn btn-primary', 'name' => 'login-button', 'id'=>'refresh']) ?> 

<?php Pjax::begin(['id' => 'countries']) ?> 

    <?= ListView::widget([ 
     'dataProvider' => $dataProvider, 
     'itemOptions' => ['class' => 'comment-item'], 
     'itemView'  => 'commentadapter', 

    ]); ?> 

<?php Pjax::end() ?> 

해당 버튼의 onclick을 새로 고침하여 목록보기 만 새로 고침하고 싶습니다. 나는 그것을하는 방법을 알고 있지만 그것은 전체 페이지를 새로 고칩니다.

답변

0

Pjax : begin() 아래의 버튼을 다시 시도해보십시오. 같은 현재 URL을 url로 설정하십시오.

<?php Pjax::begin(['id' => 'countries']) ?> 
    <?= Html::a("Refresh Countries", ['Your Current Url to view Country'], ['class' => 'btn btn-lg btn-primary']);?> 
      <?= ListView::widget([ 
       'dataProvider' => $dataProvider, 
       'itemOptions' => ['class' => 'comment-item'], 
       'itemView' => 'commentadapter', 

      ]); 
       ?> 
    <?php Pjax::end() ?> 
+0

데모에 http : 내 프로젝트 또한

$.pjax.reload('#pjaxId', {timeout : false}); 

내가 Pjax의 오버라이드 버전을 사용 //blog.neattutorials을 .com/examples/pjax/web/site/index – dungphanxuan

+0

새로 고침 페이지를 새로 고치지 않으려 고합니다. – arinze

+0

pjax로 listview를 새로 고칩니다. 주어진 예가 정확합니다. 어떤 작업에 대한 요청을하지 않고 새로 고치는 다른 방법은 없습니다. – BHoft

2

이 좋아해야 :

$("#my_tab_id").click(function() { 
      $.pjax.reload({container: '#some_pjax_id', async: false}); 
     }); 
+0

고맙습니다.하지만 작동하지 않았습니다. 작동하지 않습니다. 다시로드하거나 업데이트하지 않습니다. – arinze

+0

jquery와 함께 사용했습니다. – arinze

2

PJAX이 timeout 옵션이 있습니다 :

여기 탭에 포함하고 양식 위
use yii\widgets\Pjax; 

<?php Pjax::begin(['id' => 'some_pjax_id']) ?> 
    //your code 
<?php Pjax::end() ?> 

는 pjax 다시 내 스크립트입니다 . 이 제한 시간 동안 PJAX가 AJAX 응답을받지 못하면 전체 페이지를 다시로드합니다. 를 사용하여 다음과 같은 JS는 니펫을 :

$.pjax.defaults.timeout = false;  // For JS use case yor should manual override default timeout. 
$.pjax.reload({container: '#pjaxId'}); 

이상의 짧은 조각 :

/** 
* Custom Pjax with incremented timeout. 
* JS for Pjax updating: 
* <code> 
*  $.pjax.defaults.timeout = false;    // For JS use case yor should manual override default timeout. 
*  $.pjax.reload({container: '#pjaxId'}); 
* 
*  // OR 
*  $.pjax.reload('#pjaxId', {timeout : false}); 
* 
*  // OR for gridview with search filters 
*  $('.grid-view').yiiGridView('applyFilter'); // Thats true only if you have search Filters 
* </code> 
* 
* Note: In more cases ID of widget should be static, because widgetId is autoincremented and browser version of page may be not up-to-date. 
*/ 
class Pjax extends \yii\widgets\Pjax 
{ 
    /** 
    * @var int Timeout {@link \yii\widgets\Pjax::$timeout}. 
    *   For JS use case yor should manual override defaults ( $.pjax.defaults.timeout = false; ). 
    */ 
    public $timeout = 30000; 
} 
관련 문제