markquee
(Markjohn42)
February 5, 2013, 5:03am
1
Hi!
In _view I put a pagination 10 and add a delete link in each row but the problem is in the next page if i click the delete in my _view the one that i want to delete is not and some in the row is deleted but if im in the page1 i can delete the row that i want…
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('dept')); ?>:</b>
<?php echo CHtml::encode($data->dept); ?>
<br />
<?php
echo CHtml::link(CHtml::encode('Delete'), array('Delete', 'id'=>$data->id) ,
array(
'submit'=>array('delete', 'id'=>$data->id),
'class' => 'delete','confirm'=>'Are you sure to delete?'
)
);
?>
seenivasan
(Chellamnivas)
February 5, 2013, 7:21am
2
Dear Friend
You are absolutely correct.
This happens because htmlOption submit registers a script on the clent side.
When CListView loads pages by AJAX ,the script is not registered.
To circumvent this, we have to register a script in index.php.
views/section/index.php (Section is my model)
<h1>Sections</h1>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
<?php
Yii::app()->clientScript->registerCoreScript('yii');
Yii::app()->clientScript->registerScript('list','
$("body").on("click",".items .link",function(){
var sid=$(this).attr("id");
if(confirm("Do you want delete this item?"))
jQuery.yii.submitForm(this,"'.CHtml::normalizeUrl(array("section/delete")).'",{id:sid});
});
');
.item is the class name for CListView.
.link is the pseudoclass assigned by me for individual links.
In _view.php I have added the link.
views/section/_view.php
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
<?php echo CHtml::encode($data->name); ?>
<br />
<?php
echo CHtml::link(CHtml::encode('Delete this Item'),"#",array('id'=>$data->id,'class'=>'link'));
?>
</div>
Regards.