GridView.php
3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
namespace backend\widgets\GridView;
use Yii;
use yii\helpers\{
Html, Url, ArrayHelper
};
/**
* Class GridView
*
* @package backend\widgets\GridView
* @author FilamentV <vortex.filament@gmail.com>
* @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<div class='ibox-content'><div class='row'>{toolbar}</div><div class='table-responsive'>{items}</div></div>\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 '<span class="glyphicon glyphicon-sort" aria-hidden="true" style="cursor: move;"></span>';
}
]], $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('<i class="glyphicon glyphicon-plus"></i>', ['create'], ['class' => 'btn btn-primary'])
. Html::a('<i class="glyphicon glyphicon-trash"></i>', ['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;
}
}