@@ -68,14 +68,22 @@ public function run()
68
68
$ filterQuery
69
69
->offset (Yii::$ app ->request ->getQueryParam ('start ' , 0 ))
70
70
->limit (Yii::$ app ->request ->getQueryParam ('length ' , -1 ));
71
+ /* Begin of fix - serverSide pagination - get pagination from server side - Yii
71
72
$dataProvider = new ActiveDataProvider(['query' => $filterQuery, 'pagination' => false]);
73
+ */
74
+ $ dataProvider = new ActiveDataProvider (['query ' => $ actionQuery , 'pagination ' => ['pageSize ' => Yii::$ app ->request ->getQueryParam ('length ' , 10 )] ]);
75
+ // End of fix - serverSide pagination - get pagination from server side - Yii
72
76
Yii::$ app ->response ->format = \yii \web \Response::FORMAT_JSON ;
73
77
try {
74
78
$ response = [
75
79
'draw ' => (int )$ draw ,
76
80
'recordsTotal ' => (int )$ originalQuery ->count (),
77
- 'recordsFiltered ' => $ actionQuery ->count (),
81
+ 'recordsFiltered ' => (int )$ dataProvider ->getTotalCount (),
82
+ /* Begin of fix - get actual data from server according to filters, offset and limit
78
83
'data' => $dataProvider->getModels(),
84
+ */
85
+ 'data ' => $ actionQuery ->all (),
86
+ // End of fix - get actual data from server according to filters, offset and limit
79
87
];
80
88
} catch (\Exception $ e ) {
81
89
return ['error ' => $ e ->getMessage ()];
@@ -96,6 +104,11 @@ public function applyOrder(ActiveQuery $query, $columns, $order)
96
104
}
97
105
98
106
foreach ($ order as $ key => $ item ) {
107
+ // Begin of fix - avoid failure on columns not being orderable
108
+ if (array_key_exists ('orderable ' , $ columns [$ item ['column ' ]]) && $ columns [$ item ['column ' ]]['orderable ' ] === 'false ' ) {
109
+ continue ;
110
+ }
111
+ // End of fix - avoid failure on columns not being orderable
99
112
$ sort = $ item ['dir ' ] == 'desc ' ? SORT_DESC : SORT_ASC ;
100
113
$ query ->addOrderBy ([$ columns [$ item ['column ' ]]['data ' ] => $ sort ]);
101
114
}
0 commit comments