Skip to content

Commit 59d8bec

Browse files
committed
#49 fix requirement attributes at DataTableColumn
1 parent 17b21f3 commit 59d8bec

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/DataTable.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use yii\helpers\Html;
1414
use yii\helpers\Inflector;
1515
use yii\helpers\Json;
16-
use yii\web\JsExpression;
1716

1817
/**
1918
* Class DataTable
@@ -149,16 +148,18 @@ private function initData()
149148
$row = [];
150149
foreach ($this->_options['columns'] as $column) {
151150
if ($column instanceof DataTableColumn) {
152-
$value = ArrayHelper::getValue($obj, $column->data);
153-
if (($pos = strrpos($column->data, '.')) !== false) {
154-
$keys = explode('.', $column->data);
155-
$a = $value;
156-
foreach (array_reverse($keys) as $key) {
157-
$a = [$key => $a];
151+
if ($column->data) {
152+
$value = ArrayHelper::getValue($obj, $column->data);
153+
if (($pos = strrpos($column->data, '.')) !== false) {
154+
$keys = explode('.', $column->data);
155+
$a = $value;
156+
foreach (array_reverse($keys) as $key) {
157+
$a = [$key => $a];
158+
}
159+
$row[$keys[0]] = $a[$keys[0]];
160+
} else {
161+
$row[$column->data] = $value;
158162
}
159-
$row[$keys[0]] = $a[$keys[0]];
160-
} else {
161-
$row[$column->data] = $value;
162163
}
163164
}
164165
}

src/DataTableColumn.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace nullref\datatable;
99

10+
use yii\base\InvalidConfigException;
1011
use yii\base\Widget;
1112
use yii\helpers\Html;
1213
use yii\helpers\Inflector;
@@ -64,8 +65,8 @@ public function init()
6465
{
6566
parent::init();
6667

67-
if ($this->data === null) {
68-
throw new InvalidConfigException(get_class($this) . '::$data must be set.');
68+
if ($this->data === null && $this->render === null) {
69+
throw new InvalidConfigException("Either 'data' or 'render' properties must be specified.");
6970
}
7071

7172
if ($this->title === null) {

0 commit comments

Comments
 (0)