2011-11-14 2 views
0

私のプロジェクトでは、ベースウィンドウのポップアップにcgridviewデータを設定しています。しかし、私はAJAXのページネーションをやろうとすると失敗します。私はcgridデータだけを持つリスト請求書という名前のビューを作った。ポップアップウィンドウでCgridView ajaxのページ設定

ビュー/ユーザー/ listInvoices.php

<div id="invoice_container" name="invoice_container"> 
<div align="right"><img src="<?php echo Yii::app()->request->baseUrl; ?>/media/images/add_button.png" name="add_invoice" id="add_invoice"></div> 
<?php 
echo "INVOICES LISTING"; 
// <a href="<?php #echo Yii::app()->createAbsoluteUrl('/studio/addInvoices') ">Add Invoice</a> 
//echo $schedules; 
?> 
<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $invoice->search($studioId), 
    'columns' => array(
     array(
      'name' => 'Invoice Number', 
      'type' => 'raw', 
      'value' => '$data->invoice_no', 
     ), 
     array(
     'name' => 'Student', 
     'type' => 'raw', 
     'value' => '$data->user_id', 
     ), 
     array(
      'name' => 'Invoice Date', 
      'type' => 'raw', 
      'value' => '$data->invoice_date', 
     ), 
     array(
      'name' => 'Invoice Amount', 
      'type' => 'raw', 
      'value' => '$data->invoice_amount', 
     ), 
     array(
      'name' => 'Status', 
      'type' => 'raw', 
      'value' => '$data->invoice_status', 
     ), 
    ), 
)); 
?> 
</div> 

私のコントローラで

私は請求書をロードするために、ユーザコントローラに要求を送信baseview.phpに。データを持つajaxが成功を返し、グリッドにインボイスコントローラのグリッドが表示されます。

ビュー/ユーザー/ baseview.php

$.ajax({ 
url:loadinvoice, 
success: function(data) { $('#invoice_controller).html(data);} 
}); 

usercontroller.php

public function actionLoadinvoice() { 
$this->renderPartial('listinvoices'); 
} 

が、私のdivの中にグリッドが改ページが動作していないAJAXによって移入されます。次のページをクリックするとブラウザがリロードされます。何がこの背後にある問題です。私はバインドする必要があると思います。バインド()または.live()でajaxページ区切りプロパティ。しかし、どうすればそれをすることができます。

+0

私が試し-INGは私のページでAjaxのリストビューを切り替えるには同じ問題を抱えているため、普通のAjaxのoptions.See以下の通りです。たとえば、$ this-> renderPartial( 'listinvoices'、null、false、true)を実行した場合//最後のパラメータを "true"に設定すると、リストビューに添付されたjsを処理し、イベントを適切にバインドします。これを2回実行すると2つのバインディングが発生し、その回避方法はわかりません。 – Samson

答えて

0

こんにちは、ajaxでグリッドビューを更新する場合は、javascriptで$ .fn.yiiGridView.update(id、options)関数を使用する必要があります。 IdはあなたのGridViewのIDで、オプションは完全な署名

/** 
    * Performs an AJAX-based update of the grid view contents. 
    * @param string the ID of the grid view container 
    * @param map the AJAX request options (see jQuery.ajax API manual). By default, 
    * the URL to be requested is the one that generates the current content of the grid view. 
    */ 
    $.fn.yiiGridView.update = function(id, options) { 
      var settings = $.fn.yiiGridView.settings[id]; 
      $('#'+id).addClass(settings.loadingClass); 
      options = $.extend({ 
        type: 'GET', 
        url: $.fn.yiiGridView.getUrl(id), 
        success: function(data,status) { 
          $.each(settings.ajaxUpdate, function() { 
            $('#'+this).html($(data).find('#'+this)); 
          }); 
          if(settings.afterAjaxUpdate != undefined) 
            settings.afterAjaxUpdate(id, data); 
          $('#'+id).removeClass(settings.loadingClass); 
        }, 
        error: function(XMLHttpRequest, textStatus, errorThrown) { 
          $('#'+id).removeClass(settings.loadingClass); 
          alert(XMLHttpRequest.responseText); 
        } 
      }, options || {}); 
      if(options.data!=undefined && options.type=='GET') { 
        options.url = $.param.querystring(options.url, options.data); 
        options.data = {}; 
      } 
      options.url = $.param.querystring(options.url, settings.ajaxVar+'='+id) 

      if(settings.beforeAjaxUpdate != undefined) 
        settings.beforeAjaxUpdate(id); 
      $.ajax(options); 
    }; 
関連する問題