Hi guys
I’ve been searching around alot for this issue and have found many similar problems, but not quite the same.
Basically my app can have up to 2 gridviews on the page. The first is always there and is a list of all courses selected by the student.
There is a CButtonColumn where the student can delete courses or add new courses.
The second gridview is the general list of courses and is stored in _courseList.php.
If the student has courses, the course list is not shown. They have to click the add course button to display the course list in order to add more courses. If the student has not chosen any courses, the course list appears by default. The problem is when I delete a course, which is done using an ajax request, if the student has no more courses selected, the course list does not appear. This is fixed by refreshing the page, but I’d like to do it by an ajax request. Here is the relevant code in my view:
// GridView Code
array
(
'class'=>'CButtonColumn',
// Update div with message on delete
'afterDelete' => 'function(link,success,data){ if(success) $("#msg").html(data); }',
'template'=>'{delete} {second}',
'header'=>'Edit',
'buttons'=>array
(
'delete' => array(
'label' => 'Delete',
'imageUrl' => Yii::app()->request->baseUrl.'/images/icons/delete.png',
'options'=>array(
'title'=>'Delete this course',
),
),
'second' => array
...
On the same page, i have this div.
I would like this div to be updated after deletion of each course so that $model->HasCourses() is evaluated and the course list is show if false.
<div id='course_list' >
<?php
// If the student has no course chsoices, display list
if (!$model->hasCourses(Yii::app()->user->id)) {
$cp = new CoursePeriod('search');
$cp->unsetAttributes();
if (isset($_GET['CoursePeriod'])) {
$cp->attributes = $_GET['CoursePeriod'];
}
echo $this->renderPartial('_courseList', array('cp'=>$cp));
}
?>
</div>
So basically if the student has no courses, the list is displayed.
But this only happens when the page is refreshed. If the last course is deleted through the GridView delete button, the gridview containing the student’s courses is updated to show zero courses, a message appears in “div id=‘msg’” confirming the deletion using afterDelete, but the second gridview containing the full list of courses is not rendered in “div id=‘course_list’”.
Obviously i’m missing a step to get the div to refresh somehow, without refreshing the whole page.
does anyone have any ideas?