Generating a "static" table in Yii?

I’ve been playing with CGridView and CListView and i’m having a hard time generating JUST a table. No pagination, no sorting, nothing.

GridView seems to be too much for this (does all the ajax stuff and what not) and ListView is too basic (I have to start extending it to make my own class to support table headers and stuff).

Am I missing something?

I’m using CArrayDataProdvider for them too if that matters.

You can switch all of that off in CGridView. Just check the class reference. You can even disable the headers and footers.

Then just create a regular table. :)

Don’t use a data provider, just the result from a regular ActiveRecord query.

It’s a regular array.

Iterate it in a foreach loop to print the rows.

Ok, I’ve gone through the class reference and got almost EVERYTHING turned off… (Currently the code below has some place holder stuff in it)

        $this->widget('application.extensions.MyGridView', array(

            'dataProvider' => $dataProvider,

            'enablePagination' => false,

            'cssFile' => false,

            'hideHeader' => false,

            'ajaxUrl' => false,

            'selectableRows' => 0,

            'skin' => false,

            'htmlOptions' => array(

                'url' => $this->getRoute()


            'enableSorting' => false,

            'template' => '{items}',

            'columns' => array(


                    'header' => '',

                    'class' => 'CCheckBoxColumn',

                    'checked' => '$data["checked"]',

                    'value' => '$data["id"]',

                    'name' => uniqid(),

                    'id' => uniqid()




                'cash_date:date:Cash Date',

                'cash_amount:money:Cash Amount',




I’m still getting

<script type="text/javascript" src="/test/assets/bb04beea/gridview/jquery.yiigridview.js"></script>

<script type="text/javascript">


jQuery(function($) {

jQuery('body').undelegate('#yt0','click').delegate('#yt0','click',function(){jQuery.ajax({'url':'/test/index.php/site/forecastsetup','cache':false,'success':function(html){jQuery("#holder").html(html)}});return false;});

jQuery('body').undelegate('#yt1','click').delegate('#yt1','click',function(){jQuery.ajax({'url':'/test/index.php/site/viewforecast','cache':false,'success':function(html){jQuery("#holder").html(html)}});return false;});





Added at the bottom of my page. Anyone happen to know what I need to do to disable all the javascript/AJAX features that it loads?

The purpose of all this is that I’m using jquery dataTables instead and just for the sake of neat code, trying to use GridView to spit out just a normal static HTML table. haha.

Why are you using a grid view when you don’t want one? :)

This is one example of not using one:

<?php if (!empty($model)) : ?>

<table class="list" width="60%">

  <thead width="60">


      <td colspan="6">

      Project Repositories




    <th width="15">Name</th>

    <th width="10">type</th>

    <th width="20">URL</th>

    <th width="20">Local Path</th>

    <th width="15">Status</th>

    <th width="20">Actions</th>




<?php foreach($model as $n=>$repository): ?>

  <tr class="<?php echo $n%2?'even':'odd';?>">

    <td width="15"><?php echo CHtml::encode($repository->name); ?></td>

    <td width="10"><?php echo CHtml::encode($repository->type); ?></td>

    <td width="20"><?php echo CHtml::encode($repository->url); ?></td>

    <td width="20"><?php echo CHtml::encode($repository->local_path); ?></td>

    <td width="15"><?php echo CHtml::encode($repository->status ? 'OK' : 'Pending'); ?></td>

    <td width="20">

      <?php echo CHtml::link('Update',array('repository/update','id'=>$repository->id, 'identifier' => $_GET['identifier'])); ?>

      <?php echo CHtml::linkButton('Delete',array(

      	  'submit'=>array('/repository/delete', 'id' => $repository->id, 'identifier' => $_GET['identifier']),

      	  'confirm'=>"Are you sure you want to delete {$repository->name}?")); ?>



<?php endforeach; ?>



<?php else: ?>

<p class="nodata"><?php echo 'No data to display'; ?></p>

<?php endif; ?>

True, I’ve thought about going with the “old” way but I dig the auto formatting and all the goodies that GridView offers.

Also trying to learn all the cool Yii things and playing with GridView is making Yii make more sense. ;)

Your next step may be to extend CGridview and override registerClientScript() with an empty or customized version. Absolutely untested.


This is all very cool. Yii is way more powerful than it appears at first… :)