title: Dynamically create CGridViews that show different data
body: <p>I'm new to Yii, and I'm having a hard time figuring this out.  I want to show multiple CGridViews on a page depending on the options that a user chooses, with each gridview only showing the records for that option.  In this case, the options are job statuses, like open, closed, in progress, etc.</p>
  
  <p>I've got some code working to show multiple grid views by looping through an array, but I'm not sure how to filter them:</p>
  
  <pre><code>$test = array(1,2,3,4,5);
  
  foreach ($test as $value) {
  
  $this-&gt;widget('zii.widgets.grid.CGridView', array(
      'id'=&gt;'job-grid',
      'dataProvider'=&gt;$model-&gt;search(),   
      'columns'=&gt;array(
          'ID',
          'CustomerCompany',
          'FirstName',
          'LastName',
          /* etc */
      ),
  ));
  
  }
  </code></pre>
  
  <p>Any ideas about how I can go about filtering each gridview from the values in the array?</p>
  
  <p>Thanks!</p>
  
  <p>UPDATE</p>
  
  <p>Ok, I figured out how to do what I was trying to do.  I'm handling it in the controller like this:</p>
  
  <pre><code>public function actionBoard()
  {
      $models = array();
  
      $statuses = JobStatus::model()-&gt;findAll();
      foreach ($statuses as $status)
      {
      $model=new Job('search');
      $model-&gt;unsetAttributes();  // clear any default values
  
      if(isset($_GET['Job']))
          $model-&gt;attributes=$_GET['Job'];
          $model-&gt;Status = $status-&gt;ID;
          $models[$status-&gt;Status] = $model;
      }
  
      $this-&gt;render('board',array('models'=&gt;$models));
  }
  </code></pre>
  
  <p>So I find all the statuses, then use the ID field to do a search, put the result in an array, then pass it to the view.  I handle it like this in the view:</p>
  
  <pre><code>foreach ($models as $status)
  {
  
  $this-&gt;widget('zii.widgets.grid.CGridView', array(
      'id'=&gt;'job-grid',
      'dataProvider'=&gt;$status-&gt;search(),
      'columns'=&gt;array(
          'ID',
          'CustomerCompany',
          'FirstName',
          'LastName',
          'Phone1',
          'Phone2',
          /* etc */
      ),
  ));
  </code></pre>
  
  <p>Basically, creating a gridview for each "status" in the array of "statuses".  Seems to work, just took some time to think of it in MVC terms instead of the old ASP.NET databinding method that I'm used to.</p>