Updating Cgridview With Yiigridview('update')

Hi guys, just a quick question: why does this button successfully refresh my grid


<button id="refresh-button">Aggiorna</button>

<?php Yii::app()->clientScript->registerScript('initRefresh',"

    $('#refresh-button').on('click',function(e) {

        e.preventDefault();

        $('#appalto-grid').yiiGridView('update');

    });

"

,CClientScript::POS_READY); ?>

But adding " $(’#appalto-grid’).yiiGridView(‘update’);" in my following script will have no effect? Here it is:


<script type="text/javascript">  

  <?php echo CHtml::ajax(array(

            'url'=>array('appalto/create'),

            'data'=> "js:$(this).serialize()",

            'type'=>'post',

            'dataType'=>'json',

            'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#dialogAppalto div.divForForm').html(data.div);

                          // Here is the trick: on submit-> once again this function!

                    $('#dialogAppalto div.divForForm form').submit(addAppalto);

                }

                else

                {

                    $('#dialogAppalto div.divForForm').html(data.div);

                    setTimeout(\"$('#dialogAppalto').dialog('close') \",3000);


                }


                $('#appalto-grid').yiiGridView('update');

 

            } ",

            ))?>;

    return false; 

 

}

 

</script>

Cheers! :)

Hi,

This line should be called when in positive response…but u r calling outside the condition. so it wont work…

$(’#appalto-grid’).yiiGridView(‘update’);

Check my below code …





'click'=>"function(){

						$.fn.yiiGridView.update('module-grid', {

					        type:'POST',

					        url:$(this).attr('href'),

					        success:function(data) {

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

					        }

					    })

					    return false;

					 }",



That Worked :) but why


fn.yiigridview.update('#the-grid-id')

and not


$('#the-grid-id).yiiGridView('update');

is the second syntax incorrect or deprecated? Cheers :)

For you information…

check this code

https://code.google…gridview.js?r=4

Yii itself uses code like you…







/**

     	* Performs an AJAX-based update of the grid view contents.

     	* @param id string the ID of the grid view container

     	* @param options 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) {

                $('#' + id).yiiGridView('update', options);

        };



[size=2]

[/size]

[size=2]i think we need second ajax options… without options there is no update method :)[/size]