Skip to content

Commit 5205ba6

Browse files
Radon8472pgunold-evc
authored andcommitted
Merge pull request #69 from Radon8472/bugfix/re-add-passing-parameters-to-cols
Fix passing custom parameters to dataTables column Closes #52
2 parents 3645c37 + 431a308 commit 5205ba6

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

CHANGELOG.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## next release
5+
## v1.1.2
66
### Added
7-
- Support for bootstrap 4 (autodetect required bootstrap version)
7+
- Support for bootstrap 4/5 (autodetect required bootstrap version)
88
- Add `dataProvider` property to `DataTable`
9-
- if set, property `data` is auto filled with models from dataProvider
9+
- if set, property `data` is autofilled with models from dataProvider
1010
- if models are found either in `dataProvider` or in `data`, column labels are loaded from
1111
`Model::attributes()`
12+
- restore support for custom column definitions ([#52])
1213

1314
## v1.1.1
1415
### Added
@@ -44,3 +45,5 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4445
## v1.0.0
4546
### Changed
4647
- Move DataTable options to protected array. Add __set and __get methods.
48+
49+
[#52]: https://github.com/NullRefExcep/yii2-datatables/issues/52

composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
{
2323
"name": "Dmytro Karpovych",
2424
"email": "ZAYEC77@gmail.com"
25+
},
26+
{
27+
"name": "Radon8472",
28+
"email": "develop@radon-software.net",
29+
"homepage": "https://github.com/Radon8472",
30+
"role": "Contributor"
2531
}
2632
],
2733
"minimum-stability": "stable",

src/DataTableColumn.php

+64-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,34 @@
77

88
namespace nullref\datatable;
99

10+
use yii\base\Arrayable;
1011
use yii\base\InvalidConfigException;
1112
use yii\base\Widget;
1213
use yii\helpers\Html;
1314
use yii\helpers\Inflector;
1415
use yii\web\JsExpression;
1516

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
1738
{
1839
/**
1940
* @var string the attribute name associated with this column.
@@ -68,6 +89,8 @@ class DataTableColumn extends Widget
6889
*/
6990
protected $filter;
7091

92+
private $_options = [];
93+
7194
/**
7295
* Check if all required properties is set
7396
*/
@@ -197,4 +220,44 @@ public function getExtraColumns()
197220
return $this->extraColumns;
198221
}
199222

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+
}
200263
}

0 commit comments

Comments
 (0)