Reputation: 833
I've been working for this for a very long time and I'm nowhere near to understanding what I'm doing so wrong (yii beginner so please show some patience with me).
I have this code in my view code
echo CHtml::dropDownList('symptomCategory',
'', // selected item from the $data
$this->getSymptomCategories(),
array(
'id'=>'categorySelectDropDown',
'prompt'=>"Select Symptom Category",
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'symptoms-grid',
'selectableRows'=>1, //ability to select one symptom at a time
'dataProvider'=>$model2->search(),
//'htmlOptions'=>array('id'=>'symptomsSelectGrid'),
'columns'=>array(
'symptomCode',
'title',
'inclusions',
'exclusions',
'symptomCategory',
),
));
And my js function is this:
$('#categorySelectDropDown').change(function()
{
var symptomCategory = $('#categorySelectDropDown').val();
$('#symptoms-grid').yiiGridView('update',
{
data: symptomCategory.serialize()
});
return false;
});
I've tried with $(this).serialize() too. Anyway.
According to examples I've found online this should work, but nope, it doesn't update the cgridview. $this->getSymptomCategories() returns an array of array('A'=>'A','B'=>'B' ect. ect.)
BTW I am creating a model2 = new Symptoms; inside a view rendered by a controller of a different model because I want to use the choice from the gridview to fill in a form of the other model. Any help, documentation (haven't found any useful online), advice, ect will be really appreciated. Thank you for oyur time
Upvotes: 0
Views: 918
Reputation: 7647
Try this way of updating yiiGridView
$.fn.yiiGridView.update('symptoms-grid', {
data: $('#symptomCategory').serialize() // your form id
});
There can be many reasons why yiiGridView seems like it is not updating, one of the them is that AJAX request is not being sent, another common reason is that search condition logic is not correct, or the requested action does not pass the post data to the model, resulting in the same data being returned, making it look like it is not updating.
See if the AJAX request going to the server from firebug/console etc. If it is going then check if the post data is correct and finally check the model+controller logic is correct and the criteria of CActiveDataProvider
is reflecting your search condition
Upvotes: 1