title: Yii Update CGridView based on dropdown select
body: <p><strong>FOUND A SOLUTION CHECK END OF THIS POST</strong></p>
  
  <p>I'm been working on this for 4 weeks and I haven't made any headway. I have found tons of similar examples online and yet everything I tried I couldn't get to work. So I had to burden the community with another of my questions.</p>
  
  <p>I have a model/table called tbl_symptoms/Symptoms which has 7 columns/attributes:
  id, symptomCode,  title, shortTitle, inclusions, exclusions, symptomCategory.</p>
  
  <p>I use a dropdown select (which gets populated from a table on the server that just has the symptom categories in one column).</p>
  
  <p>While I can get the gridview to populate with ALL the symptoms, I can't get it to only populate with the same category symptoms as the dropdown.</p>
  
  <p>This is the last solution I tried out (right now it's not even rendering the gridview, but even when it did I had other problems, so I'm just posting the code so you guys have a point of reference about potential solutions):</p>
  
  <p><strong>Symptoms.php search function:</strong></p>
  
  <pre><code>public function search()
  {
      $criteria=new CDbCriteria;
  
  
      $criteria-&gt;compare('symptomCategory',$this-&gt;symptomCategory,true);
  
  
      return new CActiveDataProvider($this, array(
          'criteria'=&gt;$criteria,
      ));
  }
  </code></pre>
  
  <p><strong>SiteController.php functions I'm using:</strong></p>
  
  <pre><code>//returns symptom categories that the user can choose to pick a symptom
  public static function getSymptomCategories()
  {
      return CHtml::listData(Yii::app()-&gt;db-&gt;createCommand()-&gt;select('category')-&gt;from('tbl_symptomcategory')-&gt;queryAll(), 'category', 'category');
  }
  
  public function actionLoadSymptoms()
  {
      $symptomsModel = new Symptoms;
  
      if (isset($_POST)){
          $symptomsModel-&gt;attributes = $_POST;
          $dataProvider = $symptomsModel-&gt;search();
          $this-&gt;renderPartial('_searchSymptomsView', array('dataProvider' =&gt; $dataProvider));
      }
  }
  </code></pre>
  
  <p><strong>view file _seachSymptomsView:</strong></p>
  
  <pre><code>    &lt;?php $this-&gt;widget('zii.widgets.grid.CGridView', array(
      'id'=&gt;'searchSymptomsGrid',
      'dataProvider'=&gt;$dataProvider,
      'columns'=&gt;array(
          'symptomCode',
          'title',
          'inclusions',
          'exclusions',
          'symptomCategory',
          )
          ));
          ?&gt;
  </code></pre>
  
  <p><strong>search.php functions:</strong></p>
  
  <pre><code>&lt;!-- Select symptom category dropdown menu --&gt;
  &lt;div class="search-form"&gt;
          &lt;?php 
              echo $form-&gt;labelEx($model, 'symptomCategory'); 
              echo $form-&gt;dropDownList($model, 'symptomCategory', 
                      $this-&gt;getSymptomCategories(),
                      array( 'id'=&gt;'symptomSelectDropdown',
                             'ajax'=&gt;array('type'=&gt;'POST',
                                          'url'=&gt;CController::createUrl('SiteController/loadSymptoms'),
                                          'replace'=&gt;'#symptomSelectDiv'
                              )));
  
             ?&gt;
  
             &lt;!-- select symptom --&gt;
  &lt;div class="row" id="symptomSelectDiv"&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>This code is based on a similar question asked here but I couldn't get it to work like everything else I've tried.
  Any help is greatly appreciated, thank you.</p>
  
  <p><strong>SOLUTION I CAME UP WITH</strong> (for future reference)</p>
  
  <p>Symptoms model search function: pretty much the default constructed function, but I commented out everything except the symptomCategory which is what I wanted to base my search on.</p>
  
  <p>search view file: (revelant stuff)</p>
  
  <pre><code>   Yii::app()-&gt;clientScript-&gt;registerScript('search', "
          $('#symptomSelectDiv').hide();
          $('#categorySelectDropDown').change(function(){
              $('#symptomSelectDiv').show();
              $('#symptoms-grid').yiiGridView('update', {
                  data: $(this).serialize()
              });
              return false;
          });
   "); 
      ?&gt;
       &lt;h1&gt;Welcome to the search for symptoms page &lt;/h1&gt;
  
      &lt;div class="form"&gt;
      &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
  'id'=&gt;'search-form',
  'enableClientValidation'=&gt;true,
  'clientOptions'=&gt;array(
      'validateOnSubmit'=&gt;true,
  ),
      )); ?&gt;
  
  
  
   &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  &lt;!-- Select symptom category dropdown menu --&gt;
  &lt;div class="search-form"&gt;
          &lt;?php        $this-&gt;renderPartial('_searchCategory',array('model'=&gt;$model)); ?&gt;
  &lt;/div&gt;
  
  
             &lt;!-- select symptom --&gt;
  &lt;div class="row" id="symptomSelectDiv" &gt;
      &lt;?php $this-&gt;widget('zii.widgets.grid.CGridView', array(
              'id'=&gt;'symptoms-grid',
              'dataProvider'=&gt;$model-&gt;search(),
              'columns'=&gt;array(
                  'symptomCode',
                  'title',
                  'inclusions',
                  'exclusions',
                  'symptomCategory',
  
              ),
      )); ?&gt;
  &lt;/div&gt;
  
  
  
  &lt;div class="row buttons"&gt;
      &lt;?php  echo CHtml::submitButton('Search');  ?&gt;
  &lt;/div&gt;
  
  
  
     &lt;?php $this-&gt;endWidget(); ?&gt;
  </code></pre>
  
  <p>_searchCategory.php view:</p>
  
  <pre><code>  &lt;php $form=$this-&gt;beginWidget('CActiveForm', array(
  'action'=&gt;Yii::app()-&gt;createUrl($this-&gt;route),
  'method'=&gt;'get', 
    )); ?&gt;
  &lt;!-- form is automatically submitted when dropdown selection changes --&gt;
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;label($model,'symptomCategory'); ?&gt;
      &lt;?php echo $form-&gt;dropDownList($model, 'symptomCategory',
                                              $this-&gt;getSymptomCategories(),
                                              array('submit'=&gt;'',
                                                    'id'=&gt;'categorySelectDropDown',
                                                    'prompt'=&gt;"Select Symptom Category")); ?&gt;
  
  &lt;/div&gt;
  
  
     &lt;?php $this-&gt;endWidget(); ?&gt;
  </code></pre>