簡體   English   中英

彈出窗口中的CgridView Ajax分頁

[英]CgridView ajax pagination in popup window

在我的項目中,我正在將cgridview數據填充到基本窗口中的彈出窗口。 但是當我嘗試執行ajax分頁時,它失敗了。 我已經做了一個僅列出帶有Cgrid數據的名為列表發票的視圖。

查看/用戶/ 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分頁無法填充網格。 當我單擊下一頁時,瀏覽器將重新加載。 這是什么背后的問題。 我認為我需要在.bind()或.live()中綁定ajax分頁屬性。 但是我該怎么做。

您好,如果您想使用Ajax更新網格視圖,則應在javascript中使用$ .fn.yiiGridView.update(id,options)函數。 id是您的gridview的id,options只是常規的ajax選項。請參見下面的完整簽名

 /**
     * 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);
    };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM