简体   繁体   中英

CgridView ajax pagination in popup window

in my project i am populating a cgridview data to a popup in my base window. but when i tried doing ajax pagination it gets fails. i have made a view named list invoices having the cgrid data only.

view/user/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>

in my controller

on the baseview.php i send a request to the user controller to load invoice. an the ajax return success with the data a populate the grid onto the invoice controller grid.

view/user/baseview.php

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

usercontroller.php

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

but in my div the grid gets populated by the ajax pagination is not working. when i click the next page the browser gets reloaded. whats is the issue behind this. i think i need to bind the ajax pagination property in .bind() or .live(). but how can i do that.

Hi if you want to update the grid view with ajax you should use $.fn.yiiGridView.update(id,options) function in javascript. Id is the id of your gridview and options are just regular ajax options.See below for full signature

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM