* @copyright (c), Thread */ class GridView extends \yii\grid\GridView { public $tableOptions = ['class' => 'table table-striped']; public $options = ['class' => 'ibox float-e-margins']; public $layout = "{title}\n
{toolbar}
{items}
\n{pager}"; public $useSortable = false; public $sortableUrl = 'sortable'; public $title = ''; public $toolbar = false; public function init() { if ($this->useSortable == true) { $this->tableOptions = ArrayHelper::merge($this->tableOptions, [ 'class' => 'table table-striped sorted_table', 'id' => 't' . $this->id, 'data' => [ 'sortableUrl' => Url::toRoute($this->sortableUrl), 'csrf' => Yii::$app->getRequest()->csrfToken, ] ]); $this->columns = ArrayHelper::merge([[ 'headerOptions' => [ 'class' => 'glyphicon glyphicon-indent-right' ], 'format' => 'raw', 'value' => function () { return ''; } ]], $this->columns); } parent::init(); } /** * Returns the options for the grid view JS widget. * @return array the options */ protected function getClientOptions() { if (isset($this->filterUrl)) { $filterUrl = $this->filterUrl; } else { $request = Yii::$app->getRequest(); $baseUrl = $request->getBaseUrl(); $filterUrl = substr($request->getUrl(), strlen($baseUrl)); } $id = $this->filterRowOptions['id']; $filterSelector = "#$id input, #$id select"; if (isset($this->filterSelector)) { $filterSelector .= ', ' . $this->filterSelector; } return [ 'filterUrl' => Url::toRoute($filterUrl), 'filterSelector' => $filterSelector, ]; } /** * @inheritdoc * @param string $name * @return bool|string */ public function renderSection($name) { switch ($name) { case '{title}': return $this->renderTitle(); case '{toolbar}': return $this->renderToolbar(); case '{items}': return $this->renderItems(); case '{pager}': return $this->renderPager(); case '{sorter}': return $this->renderSorter(); default: return false; } } /** * @return string */ public function renderTitle() { $titleRow = Html::beginTag('div', ['class' => 'ibox-title']) . Html::tag('div', $this->renderSummary(), ['class' => 'ibox-tools']) . Html::endTag('div'); return $titleRow; } /** * @return string */ public function renderToolbar() { $content = Html::a('', ['create'], ['class' => 'btn btn-primary']) . Html::a('', ['trash'], ['class' => 'btn btn-info']); // $render = Html::tag('div', '', ['class' => 'col-sm-5 m-b-xs']) . Html::tag('div', '', ['class' => 'col-sm-5 m-b-xs']) . Html::tag('div', $content, ['class' => 'col-sm-2 btn-group btn-group-sm', 'role' => 'group']); return isset($toolbar) ? $render : null; } }