How can I update Yii's CListView when a new record was added triggered by an AJAX call?

和自甴很熟 提交于 2020-01-05 07:38:29

问题


Yesterday I was introduced to the CListView and could manage to display all the information i want about my records, and in the format i want. I have a 'create' button (add a new contact), which opens a modal pop up window with the corresponding fields. When this window is closed, i return to the CListView, and here is my issue: i've been trying to update the CListView (without any luck, clearly).

I believe it should be easy to update the clistview with this call: $.fn.yiiListView.update('CListViews's ID'), but i can't find the proper event that should trigger this call.

Next, i post what i would think is the relevant code:

Button

echo CHtml::ajaxButton ("Create",
                          CController::createUrl('/contacts/create'),
                          array('onclick'=>'
                                    $("#createContact").dialog("open");
                                    return false;',
                                    'update'=>'#createContact'), 
                          array('id'=>'showCreateContactDialog'));?>

CListView

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>new CArrayDataProvider($model->contacts, array('pagination'=>array('pageSize'=>5,),)),
    'itemView'=>'_view',
    'emptyText'=>'empty',
    'template'=>"{items}\n{pager}", 
    'pagerCssClass'=>'page-number',
    'id'=>'ajaxListView',
));?>

Any help is more than welcome!! Hope this helps someone eventually as well.


回答1:


If I understand correctly, your problem is finding what to trigger the CListView update with (the JS update snippet you provide should work fine).

Probably the jQuery dialog event close is what you are looking for; it will get triggered after the dialog has been closed. Alternatively, there is also a beforeClose event that has the additional capability to prevent the dialog from closing.



来源:https://stackoverflow.com/questions/6322382/how-can-i-update-yiis-clistview-when-a-new-record-was-added-triggered-by-an-aja

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!