File tree 4 files changed +29
-3
lines changed
4 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 2
2
All notable changes to this project will be documented in this file.
3
3
This project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
4
4
5
+ ## v1.1.3
6
+ ### Added
7
+ - ` DataTableAction ` ` query ` parameter can be ` Closure `
8
+
5
9
## v1.1.2
6
10
### Added
7
11
- Support for bootstrap 4/5 (autodetect required bootstrap version)
@@ -46,4 +50,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
46
50
### Changed
47
51
- Move DataTable options to protected array. Add __ set and __ get methods.
48
52
49
- [ #52 ] : https://github.com/NullRefExcep/yii2-datatables/issues/52
53
+ [ #52 ] : https://github.com/NullRefExcep/yii2-datatables/issues/52
Original file line number Diff line number Diff line change @@ -286,6 +286,17 @@ public function actions()
286
286
287
287
If you need to get some relation data you can call ` join ` or similar methods from ` $query ` in ` applyFilter ` closure.
288
288
289
+ You may also specify a closure for ` query ` in ` DataTableAction ` config if you need complex query like in the following code:
290
+ ``` php
291
+ /** ... */
292
+ 'query' => function() {
293
+ $calculatedValue = calculate_value_for_query();
294
+
295
+ return Model::find()->where(['calculated_value' => $calculatedValue]);
296
+ },
297
+ /** ... */
298
+ ```
299
+
289
300
And add options to widget:
290
301
291
302
``` php
Original file line number Diff line number Diff line change 28
28
29
29
"homepage" : " https://github.com/Radon8472" ,
30
30
"role" : " Contributor"
31
+ },
32
+ {
33
+ "name" : " Oleksandr Lynnyk" ,
34
+
35
+ "homepage" : " https://github.com/alxlnk" ,
36
+ "role" : " Contributor"
31
37
}
32
38
],
33
39
"minimum-stability" : " stable" ,
Original file line number Diff line number Diff line change 8
8
namespace nullref \datatable ;
9
9
10
10
11
+ use Closure ;
11
12
use Yii ;
12
13
use yii \base \Action ;
13
14
use yii \base \InvalidConfigException ;
@@ -37,7 +38,7 @@ class DataTableAction extends Action
37
38
public $ requestMethod = self ::REQUEST_METHOD_GET ;
38
39
39
40
/**
40
- * @var ActiveQuery
41
+ * @var ActiveQuery|Closure
41
42
*/
42
43
public $ query ;
43
44
@@ -91,6 +92,10 @@ public function init()
91
92
throw new InvalidConfigException (get_class ($ this ) . '::$query must be set. ' );
92
93
}
93
94
95
+ if ($ this ->query instanceof Closure) {
96
+ $ this ->query = call_user_func ($ this ->query );
97
+ }
98
+
94
99
if ($ this ->formatData === null ) {
95
100
$ this ->formatData = function ($ query , $ columns ) {
96
101
$ rows = [];
@@ -249,4 +254,4 @@ public function formatResponse($response)
249
254
250
255
return $ response ;
251
256
}
252
- }
257
+ }
You can’t perform that action at this time.
0 commit comments