|
7 | 7 |
|
8 | 8 | namespace nullref\datatable;
|
9 | 9 |
|
| 10 | +use yii\base\Arrayable; |
10 | 11 | use yii\base\InvalidConfigException;
|
11 | 12 | use yii\base\Widget;
|
12 | 13 | use yii\helpers\Html;
|
13 | 14 | use yii\helpers\Inflector;
|
14 | 15 | use yii\web\JsExpression;
|
15 | 16 |
|
16 |
| -class DataTableColumn extends Widget |
| 17 | +/** |
| 18 | + * Class DataTableColumn |
| 19 | + * |
| 20 | + * @package nullref\datatable |
| 21 | + * |
| 22 | + * Features |
| 23 | + * |
| 24 | + * @property string $type possible values (num, num-fmt, html-num, html-num-fmt, html, string) |
| 25 | + * @property bool $orderable Using this parameter, you can remove the end user's ability to order upon a column. |
| 26 | + * @property bool $searchable Using this parameter, you can define if DataTables should include this column in the filterable data in the table |
| 27 | + * @property bool $visible show and hide columns dynamically through use of this option |
| 28 | + * @property string $width This parameter can be used to define the width of a column, and may take any CSS value (3em, 20px etc). |
| 29 | + * @property string $cellType Change the cell type created for the column - either TD cells or TH cells |
| 30 | + * @property string $contentPadding Add padding to the text content used when calculating the optimal width for a table. |
| 31 | + * @property string $orderDataType |
| 32 | + * |
| 33 | + * Check the full list of supported properties |
| 34 | + * |
| 35 | + * @see: https://datatables.net/reference/option/columns |
| 36 | + */ |
| 37 | +class DataTableColumn extends Widget implements Arrayable |
17 | 38 | {
|
18 | 39 | /**
|
19 | 40 | * @var string the attribute name associated with this column.
|
@@ -68,6 +89,8 @@ class DataTableColumn extends Widget
|
68 | 89 | */
|
69 | 90 | protected $filter;
|
70 | 91 |
|
| 92 | + private $_options = []; |
| 93 | + |
71 | 94 | /**
|
72 | 95 | * Check if all required properties is set
|
73 | 96 | */
|
@@ -197,4 +220,44 @@ public function getExtraColumns()
|
197 | 220 | return $this->extraColumns;
|
198 | 221 | }
|
199 | 222 |
|
| 223 | + public function __get($name) |
| 224 | + { |
| 225 | + return $this->canGetProperty($name, true) |
| 226 | + ? parent::__get($name) |
| 227 | + : (isset($this->_options[$name]) ? $this->_options[$name] : null); |
| 228 | + } |
| 229 | + |
| 230 | + public function __set($name, $value) |
| 231 | + { |
| 232 | + if ($this->canSetProperty($name, true)) |
| 233 | + return parent::__set($name, $value); |
| 234 | + else |
| 235 | + return $this->_options[$name] = $value; |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * @inheritDoc |
| 240 | + */ |
| 241 | + public function fields() |
| 242 | + { |
| 243 | + return \Yii::getObjectVars($this); |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * @inheritDoc |
| 248 | + */ |
| 249 | + public function extraFields() |
| 250 | + { |
| 251 | + return $this->_options; |
| 252 | + } |
| 253 | + |
| 254 | + /** |
| 255 | + * @inheritDoc |
| 256 | + */ |
| 257 | + public function toArray(array $fields = [], array $expand = [], $recursive = true) |
| 258 | + { |
| 259 | + return $recursive |
| 260 | + ? array_merge_recursive($this->fields(), $this->extraFields()) |
| 261 | + : array_merge($this->fields(), $this->extraFields()); |
| 262 | + } |
200 | 263 | }
|
0 commit comments