Skip to content

Commit

Permalink
added a GridView widget (Close #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fps01 committed Jun 22, 2016
1 parent 9ce3b67 commit c88b0fb
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
26 changes: 26 additions & 0 deletions widgets/grid/DataColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @copyright Copyright (c) 2015 Yiister
* @license https://github.com/yiister/yii2-gentelella/blob/master/LICENSE
* @link http://gentelella.yiister.ru
*/
namespace yiister\gentelella\widgets\grid;

use yii\helpers\Html;

class DataColumn extends \yii\grid\DataColumn
{
public function renderHeaderCell()
{
$provider = $this->grid->dataProvider;
if ($this->attribute !== null && $this->enableSorting &&
($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) {
if (($direction = $sort->getAttributeOrder($this->attribute)) !== null) {
Html::addCssClass($this->headerOptions, 'sorting_' . ($direction === SORT_DESC ? 'desc' : 'asc'));
} else {
Html::addCssClass($this->headerOptions, 'sorting');
}
}
return Html::tag('th', $this->renderHeaderCellContent(), $this->headerOptions);
}
}
80 changes: 80 additions & 0 deletions widgets/grid/GridView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* @copyright Copyright (c) 2015 Yiister
* @license https://github.com/yiister/yii2-gentelella/blob/master/LICENSE
* @link http://gentelella.yiister.ru
*/

namespace yiister\gentelella\widgets\grid;

use yii\helpers\Html;

class GridView extends \yii\grid\GridView
{
/**
* @inheritdoc
*/
public $dataColumnClass = 'yiister\gentelella\widgets\grid\DataColumn';

/**
* @inheritdoc
*/
public $tableOptions = ['class' => 'table dataTable'];

/**
* @var bool whether to border grid cells
*/
public $bordered = true;

/**
* @var bool whether to condense the grid
*/
public $condensed = false;

/**
* @var bool whether to stripe the grid
*/
public $striped = true;

/**
* @var bool whether to add a hover for grid rows
*/
public $hover = false;

/**
* @inheritdoc
*/
public function init()
{
if ($this->bordered) {
Html::addCssClass($this->tableOptions, 'table-bordered');
}
if ($this->condensed) {
Html::addCssClass($this->tableOptions, 'table-condensed');
}
if ($this->striped) {
Html::addCssClass($this->tableOptions, 'table-striped');
}
if ($this->hover) {
Html::addCssClass($this->tableOptions, 'table-hover');
}
parent::init();
}

/**
* @inheritdoc
*/
public function run()
{
GridViewAsset::register($this->view);
parent::run();
}

/**
* @inheritdoc
*/
public function renderPager()
{
return Html::tag('div', parent::renderPager(), ['class' => 'dataTables_paginate paging_simple_numbers']);
}
}
20 changes: 20 additions & 0 deletions widgets/grid/GridViewAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @copyright Copyright (c) 2015 Yiister
* @license https://github.com/yiister/yii2-gentelella/blob/master/LICENSE
* @link http://gentelella.yiister.ru
*/

namespace yiister\gentelella\widgets\grid;

class GridViewAsset extends \yii\web\AssetBundle
{
public $sourcePath = '@vendor/bower/gentelella/vendors/datatables.net-bs/css';
public $css = [
'dataTables.bootstrap.min.css',
];
public $js = [];
public $depends = [
'yiister\gentelella\assets\Asset',
];
}

0 comments on commit c88b0fb

Please sign in to comment.