Hi,
I have a view containing a CGridView widget and a custom form.
When I use some of the built-in tools for the CButtonColumn, like the ‘delete’ button, I trigger an AJAX request that re-renders the specified view. So far so good.
Or almost: I noticed that the ‘delete’ button triggers $.fn.yiiGridView.update(), which apparently sends another request AFTER the delete request, to update the grid view. Why two requests?
But my main problem is that I’m trying to update the grid with a simple form, outside of the gridView, which adds an element to the list. This is how my partial view looks like, wrapped in a div with id ‘task_data’:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'task-form',
'action'=>Yii::app()->createUrl('task/addToBatch'),
)); ?>
<?=$form->errorSummary(Task::model())?>
<div class="row">
<strong>Add a task: </strong>
<?=$form->hiddenField(Batch::model(),'id',['value'=>$bid])?>
<?=$form->dropDownList(Task::model(),'id',['']+Task::model()->listActive)?>
<?=$form->error(Task::model(),'id')?>
<?=CHtml::ajaxButton('Add',Yii::app()->createUrl('task/addToBatch'),[
'update'=>'#task_data',
'type'=>'POST',
])?>
</div>
<?php $this->endWidget('Add'); ?>
</div><!-- form -->
<CGridView widget code...>
This sends the correct request, which modifies some records and renders a partial view with the grid and form.
But the returned data includes links to JS library files already there, including additional onLoad functions for the delete buttons. Therefore, when I press the ‘delete’ button after submitting the form, it triggers the ‘Are you sure?’ dialog and the ajax request multiple times.
I noticed that the asset files linked in the request have a timestamp added to their URL, such as
.../assets/a8048f13/gridview/jquery.yiigridview.js?_=1361917741284 so they are forced to be reloaded.
How can I avoid to re-load the external JS files and to re-register the grid AJAX functions? Do I necessarily have to use $.fn.yiiGridView.update() as a callback in order to re-load the js correctly?
Thanks,
gm