15
15
use Ajax \service \JArray ;
16
16
use Ajax \service \JString ;
17
17
use Ajax \semantic \html \base \HtmlSemDoubleElement ;
18
+ use Ubiquity \utils \base \UArray ;
18
19
19
20
/**
20
21
* DataTable widget for displaying list of objects
21
22
*
22
- * @version 1.1.1
23
+ * @version 1.1.2
23
24
* @author jc
24
25
* @since 2.2
25
26
*
@@ -142,7 +143,7 @@ public function compile(JsUtils $js = NULL, &$view = NULL) {
142
143
if ($ this ->_hasCheckboxes ) {
143
144
$ this ->_generateMainCheckbox ($ captions );
144
145
}
145
- $ table ->setRowCount (0 , \sizeof ($ captions ));
146
+ $ table ->setRowCount (0 , \count ($ captions ));
146
147
$ this ->_generateHeader ($ table , $ captions );
147
148
148
149
if (isset ($ this ->_compileParts ))
@@ -198,6 +199,10 @@ protected function _hideColumns() {
198
199
}
199
200
200
201
protected function _generateHeader (HtmlTable $ table , $ captions ) {
202
+ $ gbFields = $ this ->_instanceViewer ->getGroupByFields ();
203
+ if (\is_array ($ gbFields )) {
204
+ $ captions = \array_values (UArray::removeByKeys ($ captions , $ gbFields ));
205
+ }
201
206
$ table ->setHeaderValues ($ captions );
202
207
if (isset ($ this ->_sortable )) {
203
208
$ table ->setSortable ($ this ->_sortable );
@@ -217,14 +222,15 @@ protected function _generateContent($table) {
217
222
return $ this ->_generateRow ($ instance , $ fields , $ table );
218
223
});
219
224
} else {
220
- $ activeValues = array_combine ($ groupByFields , array_fill (0 , sizeof ($ groupByFields ), null ));
225
+ $ diffFields = array_values (UArray::removeByKeys ($ fields , $ groupByFields ));
226
+ $ activeValues = array_combine ($ groupByFields , \array_fill (0 , \count ($ groupByFields ), null ));
221
227
$ uuids = [];
222
- $ table ->fromDatabaseObjects ($ objects , function ($ instance ) use ($ table , $ fields , &$ activeValues , $ groupByFields , &$ uuids ) {
228
+ $ table ->fromDatabaseObjects ($ objects , function ($ instance ) use ($ table , $ fields , &$ activeValues , $ groupByFields , &$ uuids, $ diffFields ) {
223
229
$ this ->_instanceViewer ->setInstance ($ instance );
224
230
foreach ($ groupByFields as $ index => $ gbField ) {
225
231
$ this ->_generateGroupByRow ($ index , $ gbField , $ table , $ fields , $ activeValues , $ uuids );
226
232
}
227
- return $ this ->_generateRow ($ instance , $ fields , $ table , null , $ uuids );
233
+ return $ this ->_generateRow ($ instance , $ diffFields , $ table , null , $ uuids );
228
234
});
229
235
}
230
236
if ($ table ->getRowCount () == 0 ) {
@@ -287,7 +293,6 @@ protected function _generateRow($instance, $fields, &$table, $checkedClass = nul
287
293
$ checked = $ func ($ instance );
288
294
}
289
295
$ ck ->setChecked ($ checked );
290
- // $ck->setOnChange("event.stopPropagation();");
291
296
$ field = $ ck ->getField ();
292
297
$ field ->setProperty ("value " , $ dataAjax );
293
298
$ field ->setProperty ("name " , "selection[] " );
@@ -711,8 +716,8 @@ public function getGroupByFields() {
711
716
public function setGroupByFields ($ _groupByFields ) {
712
717
$ this ->_instanceViewer ->setGroupByFields ($ _groupByFields );
713
718
}
714
-
715
- public function addGroupBy ($ index ){
719
+
720
+ public function addGroupBy ($ index ) {
716
721
$ index = $ this ->_getIndex ($ index );
717
722
if ($ index !== false ) {
718
723
$ this ->_instanceViewer ->addGroupBy ($ index );
0 commit comments