Hi,
Issue: When pagination is set for the list view, ajax update/delete is not working when i am in 2nd page(or only working when i am in 1st page). I tried to find the solution in forum i could not find the related one. Please help me.
Code:
Active record Behaviour
public function getCommentDataProvider()
{
return new CArrayDataProvider($this->getComments(),array(
'pagination'=>array(
'pageSize'=>5,
),
));
}
Controller
public function actionDelete($id)
{
// we only allow deletion via POST request
if(Yii::app()->request->isPostRequest)
{
$comment = $this->loadModel($id);
if (!Yii::app()->user->isGuest && (Yii::app()->user->id == $comment->userId))
{
$comment->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if (!Yii::app()->request->isAjaxRequest) {
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
}
else {
throw new CHttpException(403,'Only comment owner can delete his comment.');
}
}
else {
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
}
_form
<div class="row buttons">
<?php if ($comment->isNewRecord) {
echo $form->hiddenField($comment, 'type');
echo $form->hiddenField($comment, 'key');
echo CHtml::hiddenField('returnUrl',Yii::app()->request->requestUri);
echo CHtml::ajaxSubmitButton('Comment',
array('/comment/comment/create'),
array(
'replace'=>'#ext-comment-form-new',
'error'=>"function(){
$('#Comment_message').css('border-color', 'red');
$('#Comment_message').css('background-color', '#fcc');
}"
),
array('id'=>'ext-comment-submit' . (isset($ajaxId) ? $ajaxId : ''))
);
} else {
echo CHtml::ajaxSubmitButton('Update',
array('/comment/comment/update', 'id'=>$comment->id),
array(
'replace'=>'#ext-comment-form-edit-'.$comment->id,
'error'=>"function(){
$('#Comment_message').css('border-color', 'red');
$('#Comment_message').css('background-color', '#fcc');
}"
),
array('id'=>'ext-comment-submit' . (isset($ajaxId) ? $ajaxId : ''))
);
}
?>
</div>
Thank you.
PS: Using Yii 1.1.8 / Windows / MySql