Skip to content

Commit 679d64d

Browse files
committed
- Require PHP >= 5.5
- Require Yii ~2.0.14 - Remove DataColumn :: rowOptions - Added DataColumn :: options
1 parent 10da554 commit 679d64d

File tree

8 files changed

+72
-129
lines changed

8 files changed

+72
-129
lines changed

README.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ Usage
3434
Example:
3535
```php
3636
$arrayRows = [];
37-
foreach(range(1, 100) as $item)
38-
{
37+
foreach(range(1, 100) as $item) {
3938
$arrayRows[] = [
4039
'id' => $item,
4140
'name' => 'Product ' . $item,
@@ -76,6 +75,7 @@ return $grid->run();
7675

7776
Response
7877
------------
78+
7979
```json
8080
{
8181
"metadata": {
@@ -106,11 +106,11 @@ Response
106106
},
107107
"pager": {
108108
"results": {
109-
"total": 100,
109+
"total": 1212,
110110
"per_page": 5
111111
},
112112
"pages": {
113-
"total": 20,
113+
"total": 243,
114114
"current": 1
115115
}
116116
},
@@ -119,6 +119,7 @@ Response
119119
"label": "Id",
120120
"attribute": "id",
121121
"description": null,
122+
"options": [],
122123
"sortable": true,
123124
"filterable": false,
124125
"header": {
@@ -130,9 +131,6 @@ Response
130131
"items": [],
131132
"options": []
132133
},
133-
"row": {
134-
"options": []
135-
},
136134
"footer": {
137135
"value": [],
138136
"options": []
@@ -142,6 +140,7 @@ Response
142140
"label": "Name",
143141
"attribute": "name",
144142
"description": null,
143+
"options": [],
145144
"sortable": true,
146145
"filterable": false,
147146
"header": {
@@ -153,9 +152,6 @@ Response
153152
"items": [],
154153
"options": []
155154
},
156-
"row": {
157-
"options": []
158-
},
159155
"footer": {
160156
"value": [],
161157
"options": []
@@ -165,6 +161,7 @@ Response
165161
"label": "Price",
166162
"attribute": "price",
167163
"description": null,
164+
"options": [],
168165
"sortable": true,
169166
"filterable": false,
170167
"header": {
@@ -176,9 +173,6 @@ Response
176173
"items": [],
177174
"options": []
178175
},
179-
"row": {
180-
"options": []
181-
},
182176
"footer": {
183177
"value": [],
184178
"options": []
@@ -188,6 +182,7 @@ Response
188182
"label": "Created At",
189183
"attribute": "created_at",
190184
"description": null,
185+
"options": [],
191186
"sortable": true,
192187
"filterable": false,
193188
"header": {
@@ -199,9 +194,6 @@ Response
199194
"items": [],
200195
"options": []
201196
},
202-
"row": {
203-
"options": []
204-
},
205197
"footer": {
206198
"value": [],
207199
"options": []
@@ -213,31 +205,31 @@ Response
213205
"id": 1,
214206
"name": "Product 1",
215207
"price": 101,
216-
"created_at": "2017-12-14 11:13:57"
208+
"created_at": "2018-04-02 17:54:52"
217209
},
218210
{
219211
"id": 2,
220212
"name": "Product 2",
221213
"price": 102,
222-
"created_at": "2017-12-14 11:13:57"
214+
"created_at": "2018-04-02 17:54:52"
223215
},
224216
{
225217
"id": 3,
226218
"name": "Product 3",
227219
"price": 103,
228-
"created_at": "2017-12-14 11:13:57"
220+
"created_at": "2018-04-02 17:54:52"
229221
},
230222
{
231223
"id": 4,
232224
"name": "Product 4",
233225
"price": 104,
234-
"created_at": "2017-12-14 11:13:57"
226+
"created_at": "2018-04-02 17:54:52"
235227
},
236228
{
237229
"id": 5,
238230
"name": "Product 5",
239231
"price": 105,
240-
"created_at": "2017-12-14 11:13:57"
232+
"created_at": "2018-04-02 17:54:52"
241233
}
242234
]
243235
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=5.4",
22-
"yiisoft/yii2": "~2.0.13",
21+
"php": ">=5.5",
22+
"yiisoft/yii2": "~2.0.14",
2323
"vivre-tech/rest-renderer": "*"
2424

2525
},

src/DataColumn.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

3-
43
namespace vivretech\rest\grid;
54

6-
75
use yii\base\BaseObject;
86
use yii\base\Model;
97
use yii\data\ActiveDataProvider;
@@ -12,7 +10,6 @@
1210
use yii\helpers\ArrayHelper;
1311
use yii\helpers\Inflector;
1412

15-
1613
class DataColumn extends BaseObject
1714
{
1815

@@ -42,6 +39,11 @@ class DataColumn extends BaseObject
4239
*/
4340
public $description;
4441

42+
/**
43+
* @var array
44+
*/
45+
public $options = [];
46+
4547
/**
4648
* @var string|array|Closure an anonymous function or a string that is used to determine the value to display in the current column.
4749
*
@@ -80,11 +82,6 @@ class DataColumn extends BaseObject
8082
*/
8183
public $visible = true;
8284

83-
/**
84-
* @var array the attributes for the row group tag.
85-
*/
86-
public $rowOptions = [];
87-
8885
/**
8986
* @var array the attributes for the header cell tag.
9087
*/
@@ -121,7 +118,6 @@ class DataColumn extends BaseObject
121118
public function renderLabel()
122119
{
123120
$label = $this->getHeaderCellLabel();
124-
125121
return $label;
126122
}
127123

@@ -170,10 +166,8 @@ public function renderFilterCell()
170166
{
171167
$selectedValue = null;
172168

173-
if (empty($this->grid->filterModel) === false)
174-
{
175-
if (in_array($this->attribute, $this->grid->filterModel->attributes()))
176-
{
169+
if (empty($this->grid->filterModel) === false) {
170+
if (in_array($this->attribute, $this->grid->filterModel->attributes())) {
177171
$selectedValue = $this->grid->filterModel->{$this->attribute};
178172
}
179173
}
@@ -209,8 +203,7 @@ protected function getHeaderCellLabel()
209203
$provider = $this->grid->dataProvider;
210204
$label = $this->label;
211205

212-
if ($this->label === null)
213-
{
206+
if ($this->label === null) {
214207

215208
if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQueryInterface) {
216209
/* @var $modelClass Model */
@@ -271,10 +264,8 @@ protected function renderDataCellContent($model, $key, $index)
271264
*/
272265
public function getDataCellValue($model, $key, $index)
273266
{
274-
if ($this->value !== null)
275-
{
276-
if (is_string($this->value))
277-
{
267+
if ($this->value !== null) {
268+
if (is_string($this->value)) {
278269
return ArrayHelper::getValue($model, $this->value);
279270
}
280271

0 commit comments

Comments
 (0)