Yii Framework Forum: How To Update The Clistview After Deletion Of Record Using Ajax Request - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Update The Clistview After Deletion Of Record Using Ajax Request

#1 User is offline   SUBHASH 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 08-November 12

Posted 31 January 2013 - 01:45 AM

here i am using the ajax request to delete the record from the clistview the record is deleting succesfully but the list view is not updating if we refresh the page then only the record is removing from the clist view can any one help here is my code

<?php
echo CHtml::link(CHtml::encode('Delete'), $this->createUrl('delete', array('id' => $data['id'])), array(// for htmlOptions
'onclick' => ' {' . CHtml::ajax(array(
'type'=>'POST',
'beforeSend' => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;else return false;}',
'url'=>$this->createUrl('delete', array('id' => $data['id'],'ajax'=>'delete')),
'complete'=>'js:function(jqXHR, textStatus){$.fn.yiiListView.update("firstlist");}'
)) .
'return false;}', // returning false prevents the default navigation to another url on a new page
)
);
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 601
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 04 February 2013 - 04:00 PM

Dear Subash

views/post/index.php
<?php $this->widget('zii.widgets.CListView', array(
	'dataProvider'=>$dataProvider,
	'itemView'=>'_view',
	'id'=>"post_list",
)); ?>


I added the following part to _view.php.
views/post/_view.php
<?php echo CHtml::ajaxLink("Delete",array("post/delete","id"=>$data->id),array(

     "beforeSend" => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;}',
     "success"=>'js:function(data){$.fn.yiiListView.update("post_list",{});}',
     "type"=>"post",

          ),array("id"=>$data->id)); ?>


This is working.

Regards.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users