ajax screen update issue

I have a gridview where I can search for items and delete them if desired. I am running into an issue where after an ajax call doing the search with a screen update, a second ajax call doing the delete and then updating the same screen causes only the data to be output minus the controls (gridview, etc). I know this is probably some collision with multiple jquery loading, but I am new at this and not sure how this is really supposed to be properly handled. Thanks




// first ajax search url call

     echo CHtml::htmlButton('<i style="text-align: left; width: 2em" class="glyphicon glyphicon-search"></i> Search',  array(

                                     'onclick'=>'js: $.ajax({

                                        type: "POST",

                                        data: {campus: $("#id_errorCampus").val(), building: $("#id_errorBuilding").val(), room: $("#id_errorRoom").val(),

                                                startDate: $("#id_errorStartTime").val(), endDate: $("#id_errorEndTime").val(),

                                                filter: $("#id_errorFilter").val()},

                                        datatype: "json",

                                        url: "' .$url. '",

                                        success: function(result){

                                                var response = $.parseJSON(result);

                                                $("#error-view").html(response.errorViewData);

                                                }

                                        })',

                                        'id'=>'id_errorSearch',

                                        'class'=>'btn btn-success',

                                        ));

public function actionSearchError()

    {

         $campus = $_POST['campus'];

         $building = $_POST['building'];

         $room = $_POST['room'];

         $startDate = $_POST['startDate'];

         $endDate = $_POST['endDate'];

         $filter = $_POST['filter'];

         $model = new MaintenanceForm();

         $gridData['errorColumns'] = $model->buildColumnFormat();

         $gridData['campuses'] = Helper::getCampuses("");

         $gridData['errorData'] = $model->getErrorData($campus,$building,$room,$startDate,$endDate,$filter);

         $gridData['id'] = 'View';

         $gridData['mode'] = 'grid';

         $result['errorViewData'] = $this->renderPartial('/maintenance/errorview', array('gridData'=>$gridData), true);

         echo CJSON::encode($result);

         yii::app()->end();

    }


// 2nd call from grid button

         $columnFormat['Delete'] = array('class'=>'CButtonColumn',

                                            'template'=>'{newdelete}',

                                            'header'=>'Delete',

                                            'headerHtmlOptions'=>array('class'=>'gridclass', 'style'=>'color:white'),

                                            'htmlOptions'=>array('style'=>'text-align:center'),

                                            'buttons'=>array(

                                                'newdelete'=>array(

                                                    'visible'=>'$data["role"] == "Administrator"',

                                                    'imageUrl'=>'images/delete.png',

                                                    'url'=>'yii::app()->createUrl("maintenance/deleteerror", array("data"=>$data["recordID"]))',

                                                     'options' => array(

                                                        'ajax' => array('type' => 'post',

                                                                        'url'=>'js:$(this).attr("href")',

                                                                        'success' => 'js:function(result){

                                                                              response =  $.parseJSON(result);

                                                                              $("#error-view").html(response.errorViewData);

                                                                        }'

                                                            )

                                                        ),

                                                   ),

                                                ),

                                             );

   public function actionDeleteError()

    {

        $id = $_GET['data'];

        $model = new MaintenanceForm();

        $model->deleteErrorData($id);

        $gridData['mode'] = 'grid';

        $gridData['errorColumns'] = $model->buildColumnFormat();

        $errorParms = yii::app()->session->get('error-params');

        $gridData['errorData'] = $model->getErrorData($errorParms['campus'],$errorParms['building'],$errorParms['room'],$errorParms['startDate'],$errorParms['endDate'],$errorParms['filter']);

        $result['errorViewData'] = $this->renderPartial('/maintenance/errorview', array('gridData'=>$gridData), true);

        echo CJSON::encode($result);

        yii::app()->end();

    }




Here is nice tutorial about how to do ajax insert,update and delete

Yii ajax form submission

An example of the issue I am seeing is that if I do the ajax update of the gridview through the search action, which works fine, if I then page the gridview, it tries to do the search action again. Why is the last action being repeated??

I have run into some strange behavior on an ajax update of a gridview. If I call a searchaction from an ajax button which does an ajax gridview update with the new array data, that works fine. But if I perform a page selection on the gridview (it is enabled), it calls the searchaction again??? What determines the action called by the gridview on a paging operation??

[color="#006400"]/* Moved from "2.0" to "1.1" and merged to the existing topic */[/color]

I think you can try to let Gii generate the CRUD pages for your target model. I believe the admin page of it already has an ajax functionality that you are trying to implement by yourself.

I mean that you could customize the "advanced search" form, and make your "newdelete" work just like the standard "delete" works.