Overview

Packages

  • bootstrap
    • behaviors
    • components
    • form
    • gii
    • helpers
    • widgets

Classes

  • TbActiveForm
  • TbAffix
  • TbAlert
  • TbBreadcrumb
  • TbButtonColumn
  • TbCollapse
  • TbDataColumn
  • TbDetailView
  • TbGridView
  • TbHeroUnit
  • TbListView
  • TbModal
  • TbNav
  • TbNavbar
  • TbPager
  • TbScrollspy
  • TbTabs
  • TbThumbnails
  • TbTypeAhead
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * TbGridView class file.
  4:  * @author Antonio Ramirez <ramirez.cobos@gmail.com>
  5:  * @author Christoffer Niska <ChristofferNiska@gmail.com>
  6:  * @copyright Copyright &copy; Christoffer Niska 2013-
  7:  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  8:  * @package bootstrap.widgets
  9:  */
 10: 
 11: Yii::import('zii.widgets.grid.CGridView');
 12: Yii::import('bootstrap.helpers.TbHtml');
 13: Yii::import('bootstrap.widgets.TbDataColumn');
 14: 
 15: /**
 16:  * Bootstrap Zii grid view.
 17:  */
 18: class TbGridView extends CGridView
 19: {
 20:     /**
 21:      * @var string|array the table style.
 22:      * Valid values are TbHtml::GRID_TYPE_STRIPED, TbHtml::GRID_TYPE_BORDERED, TbHtml::GRID_TYPE_CONDENSED and/or
 23:      * TbHtml::GRID_TYPE_HOVER.
 24:      */
 25:     public $type;
 26:     /**
 27:      * @var string the CSS class name for the pager container. Defaults to 'pagination'.
 28:      */
 29:     public $pagerCssClass = 'pagination';
 30:     /**
 31:      * @var array the configuration for the pager.
 32:      * Defaults to <code>array('class'=>'ext.bootstrap.widgets.TbPager')</code>.
 33:      */
 34:     public $pager = array('class' => 'bootstrap.widgets.TbPager');
 35:     /**
 36:      * @var string the URL of the CSS file used by this grid view.
 37:      * Defaults to false, meaning that no CSS will be included.
 38:      */
 39:     public $cssFile = false;
 40:     /**
 41:      * @var string the template to be used to control the layout of various sections in the view.
 42:      */
 43:     public $template = "{items}\n<div class=\"row-fluid\"><div class=\"span6\">{pager}</div><div class=\"span6\">{summary}</div></div>";
 44: 
 45:     /**
 46:      * Initializes the widget.
 47:      */
 48:     public function init()
 49:     {
 50:         parent::init();
 51:         $classes = array('table');
 52:         if (isset($this->type) && !empty($this->type)) {
 53:             if (is_string($this->type)) {
 54:                 $this->type = explode(' ', $this->type);
 55:             }
 56: 
 57:             foreach ($this->type as $type) {
 58:                 $classes[] = 'table-' . $type;
 59:             }
 60:         }
 61:         if (!empty($classes)) {
 62:             $classes = implode(' ', $classes);
 63:             if (isset($this->itemsCssClass)) {
 64:                 $this->itemsCssClass .= ' ' . $classes;
 65:             } else {
 66:                 $this->itemsCssClass = $classes;
 67:             }
 68:         }
 69:     }
 70: 
 71:     /**
 72:      * Creates column objects and initializes them.
 73:      */
 74:     protected function initColumns()
 75:     {
 76:         foreach ($this->columns as $i => $column) {
 77:             if (is_array($column) && !isset($column['class'])) {
 78:                 $this->columns[$i]['class'] = 'bootstrap.widgets.TbDataColumn';
 79:             }
 80:         }
 81:         parent::initColumns();
 82:     }
 83: 
 84:     /**
 85:      * Creates a column based on a shortcut column specification string.
 86:      * @param mixed $text the column specification string
 87:      * @return \TbDataColumn|\CDataColumn the column instance
 88:      * @throws CException if the column format is incorrect
 89:      */
 90:     protected function createDataColumn($text)
 91:     {
 92:         if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches)) {
 93:             throw new CException(Yii::t(
 94:                 'zii',
 95:                 'The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'
 96:             ));
 97:         }
 98:         $column = new TbDataColumn($this);
 99:         $column->name = $matches[1];
100:         if (isset($matches[3]) && $matches[3] !== '') {
101:             $column->type = $matches[3];
102:         }
103:         if (isset($matches[5])) {
104:             $column->header = $matches[5];
105:         }
106:         return $column;
107:     }
108: }
109: 
Yiistrap API documentation generated by ApiGen 2.8.0