'table table-striped table-bordered']; /** * @var array The plugin options */ public $pluginOptions = []; /** * @var boolean whether to show the grid view if [[dataProvider]] returns no data. */ public $showOnEmpty = true; public $rowOptions = []; /** * @var Closure an anonymous function that is called once BEFORE rendering each data model. * It should have the similar signature as [[rowOptions]]. The return result of the function * will be rendered directly. */ public $beforeRow; /** * @var Closure an anonymous function that is called once AFTER rendering each data model. * It should have the similar signature as [[rowOptions]]. The return result of the function * will be rendered directly. */ public $afterRow; /** * @var boolean whether to show the header section of the grid table. */ public $showHeader = true; /** * @var array the HTML attributes for the table header row. * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. */ public $headerRowOptions = []; /** * @var boolean whether to show the footer section of the grid table. */ public $showFooter = false; /** * @var string the HTML display when the content of a cell is empty */ public $emptyCell = ' '; public $levelSymbol = '–'; /** * Init the widget object. */ public function init() { parent::init(); $this->initColumns(); } /** * Runs the widget. */ public function run() { $run = parent::run(); if (!is_null($run)) return $run; if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) { $pagination = $this->dataProvider->getPagination(); $pagination->setPageSize($this->dataProvider->getTotalCount()); $header = $this->showHeader ? $this->renderTableHeader() : false; $body = $this->renderItems(); $footer = $this->showFooter ? $this->renderTableFooter() : false; $content = array_filter([ $header, $body, $footer ]); return Html::tag('table', implode("\n", $content), $this->options); } else { return $this->renderEmptyResult(); } } /** * Renders the table header. * @return string the rendering result. */ public function renderTableHeader() { $cells = []; foreach ($this->columns as $column) { /* @var $column TreeGridColumn */ $cells[] = $column->renderHeaderCell(); } $content = Html::tag('tr', implode('', $cells), $this->headerRowOptions); return "\n" . $content . "\n"; } /** * Renders the table footer. * @return string the rendering result. */ public function renderTableFooter() { $cells = []; foreach ($this->columns as $column) { /* @var $column TreeGridColumn */ $cells[] = $column->renderFooterCell(); } $content = Html::tag('tr', implode('', $cells), $this->footerRowOptions); return "
\n" . $content . "\n"; } /** * Renders the data models for the grid view. */ public function renderItems() { $rows = []; $models = array_values($this->dataProvider->getModels()); $keys = $this->dataProvider->getKeys(); $models = TaxOption::find()->normalizeTreeData($models, $this->rootParentId); foreach ($models as $index => $model) { $key = $keys[$index]; if ($this->beforeRow !== null) { $row = call_user_func($this->beforeRow, $model, $key, $index, $this); if (!empty($row)) { $rows[] = $row; } } $rows[] = $this->renderTableRow($model, $key, $index); if ($this->afterRow !== null) { $row = call_user_func($this->afterRow, $model, $key, $index, $this); if (!empty($row)) { $rows[] = $row; } } } if (empty($rows)) { $colspan = count($this->columns); return "