/** * 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 renderDataCellContent($row, $data) { if ($this->disabled !== null) { $this->checkBoxHtmlOptions['disabled'] = $this->evaluateExpression($this->disabled, array('data' => $data, 'row' => $row)); } parent::renderDataCellContent($row, $data); }
protected function renderHeaderCellContent() { $this->registerScripts(); if ($this->headerText != null) echo $this->headerText; else parent::init(); }
protected function renderHeaderCellContent() { if ($this->selectableRows === null && $this->grid->selectableRows > 1) { echo CHtml::checkBox($this->id . '_all', false, array('class' => 'select-on-check-all')); } else { if ($this->selectableRows > 1) { echo trim($this->header) !== '' ? $this->header . ' ' . CHtml::checkBox($this->id . '_all', false) : $this->grid->blankDisplay; } else { parent::renderHeaderCellContent(); } } }
protected function renderHeaderCellContent() { if (trim($this->headerTemplate) === '') { echo $this->grid->blankDisplay; return; } $item = ''; if ($this->selectableRows === null && $this->grid->selectableRows > 1) { $item = CHtml::checkBox($this->id . '_all', false, array('class' => 'select-on-check-all dropdown-toggle', 'data-toggle' => 'dropdown')); } else { if ($this->selectableRows > 1) { $item = CHtml::checkBox($this->id . '_all', false); } else { ob_start(); parent::renderHeaderCellContent(); $item = ob_get_clean(); } } ?> <div class="dropdown"> <?php echo strtr($this->headerTemplate, array('{item}' => $item)); ?> <ul class="dropdown-menu" aria-labelledby="<?php echo $this->id; ?> _all" role="menu"> <li> <?php echo CHtml::link('<i class="icon-ok"></i> ' . Yii::t('EDataTables.edt', 'Select all'), '#', array('id' => "{$this->id}-select-all", 'class' => "dropdown-select-all")); ?> </li> <li> <?php echo CHtml::link('<i class="icon-remove"></i> ' . Yii::t('EDataTables.edt', 'Deselect all'), '#', array('id' => "{$this->id}-deselect-all", 'class' => 'dropdown-deselect-all')); ?> </li> <li class="divider"></li> <li> <?php echo CHtml::link('<i class="icon-ok"></i> ' . Yii::t('EDataTables.edt', 'Select on page'), '#', array('id' => "{$this->id}-select-page", 'class' => 'dropdown-select-page')); ?> </li> <li> <?php echo CHtml::link('<i class="icon-remove"></i> ' . Yii::t('EDataTables.edt', 'Deselect on page'), '#', array('id' => "{$this->id}-deselect-page", 'class' => 'dropdown-deselect-page')); ?> </li> </ul> </div> <?php }
/** * Renders the header cell content. * This method will render a checkbox in the header when {@link selectableRows} is greater than 1 * or in case {@link selectableRows} is null when {@link CGridView::selectableRows} is greater than 1. * This method is Copyright (c) 2008-2014 by Yii Software LLC * http://www.yiiframework.com/license/ */ public function renderHeaderCellContent() { if (trim($this->headerTemplate) === '') { echo $this->grid->blankDisplay; return; } $item = ''; if ($this->selectableRows === null && $this->grid->selectableRows > 1) { /* x2modstart */ $item = CHtml::checkBox($this->id . '_all', false, array_merge(array('class' => 'select-on-check-all'), $this->headerCheckBoxHtmlOptions)); } elseif ($this->selectableRows > 1) { /* x2modstart */ $item = CHtml::checkBox($this->id . '_all', false, $this->headerCheckBoxHtmlOptions); } else { ob_start(); parent::renderHeaderCellContent(); $item = ob_get_clean(); } echo strtr($this->headerTemplate, array('{item}' => $item)); }
/** * Renders|returns the data cell content * @param int $row * @param mixed $data * @return array|void */ protected function renderDataCellContent($row, $data) { ob_start(); parent::renderDataCellContent($row, $data); $html = ob_get_contents(); ob_end_clean(); if ($this->grid->json) { return $html; } echo $html; }
/** * Renders the header cell content. * Override in order to allow for disabled and checked by default * in the scenario where selectAll is selected. */ protected function renderHeaderCellContent() { if ($this->grid->selectableRows > 1) { $checked = false; $disabled = ''; $htmlOptions = array('disabled' => $disabled); echo ZurmoHtml::checkBox($this->id . '_all', $checked, $htmlOptions); } else { parent::renderHeaderCellContent(); } }