Skip to content

Commit

Permalink
Merge pull request #69 from Radon8472/bugfix/re-add-passing-parameter…
Browse files Browse the repository at this point in the history
…s-to-cols

Fix passing custom parameters to dataTables column

Closes #52
  • Loading branch information
Radon8472 authored and pgunold-evc committed Sep 28, 2022
2 parents 3645c37 + 431a308 commit 5205ba6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

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

## v1.1.1
### Added
Expand Down Expand Up @@ -44,3 +45,5 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## v1.0.0
### Changed
- Move DataTable options to protected array. Add __set and __get methods.

[#52]: https://github.com/NullRefExcep/yii2-datatables/issues/52
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
{
"name": "Dmytro Karpovych",
"email": "ZAYEC77@gmail.com"
},
{
"name": "Radon8472",
"email": "develop@radon-software.net",
"homepage": "https://github.com/Radon8472",
"role": "Contributor"
}
],
"minimum-stability": "stable",
Expand Down
65 changes: 64 additions & 1 deletion src/DataTableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@

namespace nullref\datatable;

use yii\base\Arrayable;
use yii\base\InvalidConfigException;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Inflector;
use yii\web\JsExpression;

class DataTableColumn extends Widget
/**
* Class DataTableColumn
*
* @package nullref\datatable
*
* Features
*
* @property string $type possible values (num, num-fmt, html-num, html-num-fmt, html, string)
* @property bool $orderable Using this parameter, you can remove the end user's ability to order upon a column.
* @property bool $searchable Using this parameter, you can define if DataTables should include this column in the filterable data in the table
* @property bool $visible show and hide columns dynamically through use of this option
* @property string $width This parameter can be used to define the width of a column, and may take any CSS value (3em, 20px etc).
* @property string $cellType Change the cell type created for the column - either TD cells or TH cells
* @property string $contentPadding Add padding to the text content used when calculating the optimal width for a table.
* @property string $orderDataType
*
* Check the full list of supported properties
*
* @see: https://datatables.net/reference/option/columns
*/
class DataTableColumn extends Widget implements Arrayable
{
/**
* @var string the attribute name associated with this column.
Expand Down Expand Up @@ -68,6 +89,8 @@ class DataTableColumn extends Widget
*/
protected $filter;

private $_options = [];

/**
* Check if all required properties is set
*/
Expand Down Expand Up @@ -197,4 +220,44 @@ public function getExtraColumns()
return $this->extraColumns;
}

public function __get($name)
{
return $this->canGetProperty($name, true)
? parent::__get($name)
: (isset($this->_options[$name]) ? $this->_options[$name] : null);
}

public function __set($name, $value)
{
if ($this->canSetProperty($name, true))
return parent::__set($name, $value);
else
return $this->_options[$name] = $value;
}

/**
* @inheritDoc
*/
public function fields()
{
return \Yii::getObjectVars($this);
}

/**
* @inheritDoc
*/
public function extraFields()
{
return $this->_options;
}

/**
* @inheritDoc
*/
public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
return $recursive
? array_merge_recursive($this->fields(), $this->extraFields())
: array_merge($this->fields(), $this->extraFields());
}
}

0 comments on commit 5205ba6

Please sign in to comment.