1 <?php
2 3 4 5 6 7 8
9
10 Yii::import('zii.widgets.grid.CGridView');
11 Yii::import('bootstrap.widgets.TbDataColumn');
12
13 14 15
16 class TbGridView extends CGridView
17 {
18
19 const TYPE_STRIPED = 'striped';
20 const TYPE_BORDERED = 'bordered';
21 const TYPE_CONDENSED = 'condensed';
22
23 24 25 26
27 public $type;
28 29 30
31 public = 'pagination';
32 33 34 35
36 public = array('class'=>'bootstrap.widgets.TbPager');
37 38 39 40
41 public $cssFile = false;
42
43 44 45
46 public function init()
47 {
48 parent::init();
49
50 $classes = array('table');
51
52 if (isset($this->type))
53 {
54 if (is_string($this->type))
55 $this->type = explode(' ', $this->type);
56
57 $validTypes = array(self::TYPE_STRIPED, self::TYPE_BORDERED, self::TYPE_CONDENSED);
58
59 if (!empty($this->type))
60 {
61 foreach ($this->type as $type)
62 {
63 if (in_array($type, $validTypes))
64 $classes[] = 'table-'.$type;
65 }
66 }
67 }
68
69 if (!empty($classes))
70 {
71 $classes = implode(' ', $classes);
72 if (isset($this->itemsCssClass))
73 $this->itemsCssClass .= ' '.$classes;
74 else
75 $this->itemsCssClass = $classes;
76 }
77
78 $popover = Yii::app()->bootstrap->popoverSelector;
79 $tooltip = Yii::app()->bootstrap->tooltipSelector;
80
81 $afterAjaxUpdate = "js:function() {
82 jQuery('.popover').remove();
83 jQuery('{$popover}').popover();
84 jQuery('.tooltip').remove();
85 jQuery('{$tooltip}').tooltip();
86 }";
87
88 if (!isset($this->afterAjaxUpdate))
89 $this->afterAjaxUpdate = $afterAjaxUpdate;
90 }
91
92 93 94
95 protected function initColumns()
96 {
97 foreach ($this->columns as $i => $column)
98 {
99 if (is_array($column) && !isset($column['class']))
100 $this->columns[$i]['class'] = 'bootstrap.widgets.TbDataColumn';
101 }
102
103 parent::initColumns();
104 }
105
106 107 108 109 110 111
112 protected function createDataColumn($text)
113 {
114 if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches))
115 throw new CException(Yii::t('zii', 'The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
116
117 $column = new TbDataColumn($this);
118 $column->name = $matches[1];
119
120 if (isset($matches[3]) && $matches[3] !== '')
121 $column->type = $matches[3];
122
123 if (isset($matches[5]))
124 $column->header = $matches[5];
125
126 return $column;
127 }
128 }
129