Update Cgridview Via Ajax Button Not Working.

Hi all,

I’m trying to update a cgridview using a drop-down to select categories and an ajax button to submit the value to a controller for processing.

I have in my controller:


public function actionFilterClients {

    if (Yii::app()->request->isAjaxRequest) {

        if (isset($_POST['category_id'])) {

            $criteria = new CDbCriteria;

            $criteria->condition = "user_id=:user_id";

            $criteria->params = array(':user_id' => Yii::app()->user->id);

            $criteria->compare('category_id',$_POST['category_id'],true);


            $dataProvider = new CActiveDataProvider('Client', array(

                                    'criteria'=>$criteria,

                                ));

            $this->renderPartial('transfer_step_3' , array('dataProvider'=>$dataProvider)) ;

        }

    }

}

In my view among other things I have:


<?php $filter=$this->beginWidget('CActiveForm', array(

            'id'=>'client-filter-form',

            'enableAjaxValidation'=>false,

            'htmlOptions'=>array('class'=>'form-horizontal'),

        )); ?>

        <label for="category_id">View clients in category:</label>

        <?php echo CHtml::dropDownList('category_id','',Client::clientCategories(), array('options' => array('2'=>array('selected'=>true)))); ?>


        <?php

            echo CHtml::ajaxButton(

                'Filter Clients',

                'filterclients',

                array(

                    'type'=>'POST',

                    'update'  => 'client-grid' ,

                    'success' =>"function(data) {

         \$.fn.yiiGridView.update('client-grid');}",

                )

            );

        ?>

        <?php $this->endWidget(); ?>

and


<?php  $this->widget('bootstrap.widgets.TbGridView',array(

            'type'=>'bordered striped condensed',

            'id'=>'client-grid',

            'ajaxUpdate' => true ,

            'rowCssClassExpression'=>'($data->duplicate==2)?"yellow"<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />$data->duplicate==1?"blue":"")',

            'dataProvider'=>(isset($dataProvider)?$dataProvider:$clients->moveclients()),

            'template'=>"{items}\n{pager}",

            'columns'=>array(

                array(

                    'class'=>'CCheckBoxColumn',

                    'selectableRows'=>2,

                    'id'=>'clients',

                ),

                'name',

                'surname',

                'telephone',

                'email',

                array(

                    'header'=>'Category',

                    'name' => 'category_title',

                    'type' => 'raw',

                    'value' => '$data->category->title',

                ),

            ),

        )); ?>

Because this is a multi-step form, the cgridview dataprovider defaults to listing all clients ($clients->moveclients() lists all clients).

The ajax button posts the category_id to the client/filterclients url correctly.

I can see with firebug that actionFilterClients returns the rendered html correctly (with the correct clients) but the gridview is not updated…

Any ideas on why not?

Thanks in advance!

Hi,

can you add this in tbgridview and check




'afterAjaxUpdate'=>'function(id, data){

	$.fn.yiiGridView.update('client-grid');


}



I hope it will solve your problem :)