Skip to content

Commit 17b21f3

Browse files
committed
refactoring and prepare v1.1.0
1 parent 7ec9162 commit 17b21f3

11 files changed

+66
-44
lines changed

CHANGELOG.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,33 @@
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-
## v1.0.0
6-
### Changed
7-
- Move DataTable options to protected array. Add __set and __get methods.
8-
9-
## v1.0.1
5+
## v1.1.0
6+
### Added
7+
- Add `sClass` property for `DataTableColumn` class
8+
- Add `title` property for `LinkColumn` class
109
### Changed
1110
- Improve README
11+
- Change `options` property to `linkOptions` at LinkColumn class
12+
- Move asset classes to separate directory
13+
- Update minimal php version to 5.5.0
14+
- Reverse order CHANGELOG
15+
16+
## v1.0.4
17+
### Added
18+
- php 7.2 compatibility
1219

20+
## v1.0.3
21+
### Added
22+
- Data and response formatting in DataTableAction
1323

1424
## v1.0.2
1525
### Fixed
1626
- Server-side pagination
1727

28+
## v1.0.1
29+
### Changed
30+
- Improve README
1831

19-
## v1.0.3
20-
### Added
21-
- Data and response formatting in DataTableAction
32+
## v1.0.0
33+
### Changed
34+
- Move DataTable options to protected array. Add __set and __get methods.

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ To pass them as widget options:
4545
'name',
4646
'email'
4747
],
48-
'withColumnFilter' => true
48+
'withColumnFilter' => true,
4949
]) ?>
5050
```
5151

52-
## Specifies header label
52+
## Specifies header label and css class for cell
5353

5454
```php
5555
<?= \nullref\datatable\DataTable::widget([
@@ -58,6 +58,7 @@ To pass them as widget options:
5858
[
5959
'data' => 'active',
6060
'title' => 'Is active',
61+
'sClass' => 'active-cell-css-class',
6162
],
6263
],
6364
]) ?>
@@ -72,7 +73,7 @@ To pass them as widget options:
7273
[
7374
'class' => 'nullref\datatable\LinkColumn',
7475
'url' => ['/model/delete'],
75-
'options' => ['data-confirm' => 'Are you sure you want to delete this item?', 'data-method' => 'post'],
76+
'linkOptions' => ['data-confirm' => 'Are you sure you want to delete this item?', 'data-method' => 'post'],
7677
'label' => 'Delete',
7778
],
7879
],
@@ -84,7 +85,7 @@ Properties of `LinkColumn`:
8485
- `label` - text placed in `a` tag;
8586
- `title` - header title of column;
8687
- `url` - will be passed to `Url::to()`;
87-
- `options` - HTML options of the `a` tag;
88+
- `linkOptions` - HTML options of the `a` tag;
8889
- `queryParams` - array of params added to `url`, `['id']` by default;
8990
- `render` - custom render js function. E.g:
9091
```php
@@ -121,11 +122,11 @@ You ca add column filtering functionality by setting option `withColumnFilter` t
121122
[
122123
'data' => 'active',
123124
'title' => \Yii::t('app', 'Is active'),
124-
'filter' => [ 'true' => 'Yes', 'false' => 'No' ]
125+
'filter' => ['true' => 'Yes', 'false' => 'No'],
125126
],
126127
[
127128
'data' => 'last_connection',
128-
'filter' => false
129+
'filter' => false,
129130
],
130131
],
131132
]) ?>
@@ -167,8 +168,8 @@ Cell rendering or filter can be customized using `\nullref\datatable\DataTableCo
167168
```php
168169
'assetManager' => [
169170
'bundles' => [
170-
'nullref\datatable\DataTableAsset' => [
171-
'styling' => \nullref\datatable\DataTableAsset::STYLING_BOOTSTRAP,
171+
'nullref\datatable\assets\DataTableAsset' => [
172+
'styling' => \nullref\datatable\assets\DataTableAsset::STYLING_BOOTSTRAP,
172173
]
173174
],
174175
],
@@ -187,15 +188,15 @@ Bootstrap tables require the class 'table', so you'll need to add the 'table' cl
187188
'columns' => [
188189
'id',
189190
'name',
190-
'email'
191+
'email',
191192
],
192193
]) ?>
193194
```
194195

195196
## Custom assets
196-
It's posible to use custom styles and scripts:
197+
It's possible to use custom styles and scripts:
197198
```php
198-
'nullref\datatable\DataTableAsset' => [
199+
'nullref\datatable\assets\DataTableAsset' => [
199200
'sourcePath' => '@webroot/js/plugin/datatables/',
200201
'js' => [
201202
'jquery.dataTables-1.10-cust.js',

src/DataTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace nullref\datatable;
99

10+
use nullref\datatable\assets\DataTableAsset;
1011
use yii\base\Widget;
1112
use yii\helpers\ArrayHelper;
1213
use yii\helpers\Html;

src/DataTableColumn.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DataTableColumn extends Widget
2424
* If it is not set [[\yii\helpers\Inflector::camel2words()]] will be used to get a label.
2525
*/
2626
public $title;
27+
2728
/**
2829
* @var array the HTML attributes for the filter input fields. This property is used in combination with
2930
* the [[filter]] property. When [[filter]] is not set or is an array, this property will be used to
@@ -35,10 +36,16 @@ class DataTableColumn extends Widget
3536
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
3637
*/
3738
public $filterInputOptions = ['class' => 'form-control', 'id' => null];
39+
3840
/** @var JsExpression Javascript (function or expression) used to display the filter */
3941
public $renderFilter;
42+
4043
/** @var JsExpression Javascript (function) used to display the value. */
4144
public $render;
45+
46+
/** @var string CSS class for column cell */
47+
public $sClass = '';
48+
4249
/**
4350
* @var array|null|false Indicating if a filter will be displayed or not.
4451
*
@@ -50,6 +57,9 @@ class DataTableColumn extends Widget
5057
*/
5158
private $filter;
5259

60+
/**
61+
* Check if all required properties is set
62+
*/
5363
public function init()
5464
{
5565
parent::init();
@@ -71,11 +81,11 @@ public function init()
7181
}
7282
}
7383

84+
/**
85+
* @return JsExpression
86+
*/
7487
public function getJsRender()
7588
{
76-
$jsTitle = Html::encode($this->label);
77-
$jsClass = Html::encode($this->filterInputOptions['class']);
78-
$jsId = $this->filterInputOptions['id'] ? Html::encode($this->filterInputOptions['id']) : $this->getId();
7989
if (is_array($this->filter)) {
8090
$select = "switch (data) {";
8191

@@ -93,6 +103,9 @@ public function getJsRender()
93103
}
94104
}
95105

106+
/**
107+
* @return JsExpression
108+
*/
96109
public function getJsFilter()
97110
{
98111
$jsTitle = Html::encode($this->label);
@@ -160,7 +173,7 @@ public function getFilter()
160173
/**
161174
* @param array|false|null $filter
162175
*/
163-
public function setFilter($filter): void
176+
public function setFilter($filter)
164177
{
165178
$this->filter = $filter;
166179
}

src/LinkColumn.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,26 @@
1111
use yii\helpers\Json;
1212
use yii\web\JsExpression;
1313

14-
class LinkColumn extends \yii\base\BaseObject
14+
class LinkColumn extends DataTableColumn
1515
{
1616
public $queryParams = ['id'];
1717
public $url;
18-
public $title;
1918
public $label;
20-
public $options = [];
21-
public $data = null;
22-
public $render;
19+
public $linkOptions = [];
2320
public $searchable = false;
2421
public $orderable = false;
2522

2623
public function init()
2724
{
28-
if (empty($this->options['id'])) {
29-
$this->options['id'] = 'link';
25+
if (empty($this->linkOptions['id'])) {
26+
$this->linkOptions['id'] = 'link';
3027
}
3128

3229
if (!isset($this->render)) {
3330
$this->render = new JsExpression('function render(data, type, row, meta){
3431
var p = ' . Json::encode($this->queryParams) . ';
3532
var q = {};for (var i = 0; i < p.length; i++) {q[p[i]] = row[p[i]];}
36-
var link = jQuery(\'' . Html::a($this->label, $this->url, $this->options) . '\');
33+
var link = jQuery(\'' . Html::a($this->label, $this->url, $this->linkOptions) . '\');
3734
var paramPrefix = ((link.attr("href").indexOf("?") < 0) ? "?" : "&");
3835
link.attr("id", link.attr("id") + meta.row);link.attr("href", link.attr("href") + paramPrefix + jQuery.param(q));
3936
return link.get()[0].outerHTML;}');

src/DataTableAsset.php renamed to src/assets/DataTableAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Serhiy Vinichuk <[email protected]>
66
*/
77

8-
namespace nullref\datatable;
8+
namespace nullref\datatable\assets;
99

1010

1111
use yii\web\AssetBundle;

src/DataTableBaseAsset.php renamed to src/assets/DataTableBaseAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Serhiy Vinichuk <[email protected]>
66
*/
77

8-
namespace nullref\datatable;
8+
namespace nullref\datatable\assets;
99

1010

1111
use yii\web\AssetBundle;

src/DataTableBootstrapAsset.php renamed to src/assets/DataTableBootstrapAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Serhiy Vinichuk <[email protected]>
66
*/
77

8-
namespace nullref\datatable;
8+
namespace nullref\datatable\assets;
99

1010

1111
use yii\web\AssetBundle;

src/DataTableDefaultAsset.php renamed to src/assets/DataTableDefaultAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Serhiy Vinichuk <[email protected]>
66
*/
77

8-
namespace nullref\datatable;
8+
namespace nullref\datatable\assets;
99

1010

1111
use yii\web\AssetBundle;

DataTableFaAsset.php renamed to src/assets/DataTableFaAsset.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@
55
* @author Serhiy Vinichuk <[email protected]>
66
*/
77

8-
namespace nullref\datatable;
8+
namespace nullref\datatable\assets;
99

1010

1111
use yii\web\AssetBundle;
1212

1313
class DataTableFaAsset extends AssetBundle
1414
{
15+
public $css = [
16+
'dataTables.fontAwesome.css',
17+
];
18+
1519
public $depends = [
1620
DataTableBaseAsset::class,
1721
];
18-
19-
public function init()
20-
{
21-
parent::init();
22-
$this->css[] = 'dataTables.fontAwesome.css';
23-
}
24-
2522
}

src/DataTableJuiAsset.php renamed to src/assets/DataTableJuiAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author Serhiy Vinichuk <[email protected]>
66
*/
77

8-
namespace nullref\datatable;
8+
namespace nullref\datatable\assets;
99

1010

1111
use yii\web\AssetBundle;

0 commit comments

Comments
 (0)