/** * Creates column objects and initializes them. * Automatically add hidden checkbox column. */ protected function initColumns() { parent::initColumns(); if ($this->selectableRows == 0) { return; } //define primaryKey expression if ($this->dataProvider instanceof CActiveDataProvider) { $primaryKey = '$data->primaryKey'; } else { $primaryKey = '$data["' . $this->dataProvider->keyField . '"]'; } $checkedExpression = 'isset($_GET["' . $this->selVar . '"]) ? in_array(' . $primaryKey . ', is_array($_GET["' . $this->selVar . '"]) ? $_GET["' . $this->selVar . '"] : array($_GET["' . $this->selVar . '"])) : false;'; //if gridview already has user defined Checkbox column --> set "checked" and exit //thanks to Horacio Segura http://www.yiiframework.com/extension/selgridview/#c7346 foreach ($this->columns as $col) { if ($col instanceof CCheckBoxColumn) { $col->checked = $checkedExpression; $col->init(); return; } } //creating hidden checkbox column $checkboxColumn = new CCheckBoxColumn($this); $checkboxColumn->checked = $checkedExpression; $checkboxColumn->htmlOptions = array('style' => 'display:none'); $checkboxColumn->headerHtmlOptions = array('style' => 'display:none'); $checkboxColumn->init(); $this->columns[] = $checkboxColumn; }
protected function renderHeaderCellContent() { $this->registerScripts(); if ($this->headerText != null) echo $this->headerText; else parent::init(); }
public function init() { // allows width to be set for column using width property if ($this->width) { $this->headerHtmlOptions['style'] = isset($this->headerHtmlOptions['style']) ? $this->headerHtmlOptions['style'] : ''; $this->htmlOptions['style'] = isset($this->htmlOptions['style']) ? $this->htmlOptions['style'] : ''; $this->headerHtmlOptions['style'] .= 'width: ' . $this->width . ';'; $this->htmlOptions['style'] .= 'width: ' . $this->width . ';'; } return parent::init(); }