Skip to content

Commit 3c4d036

Browse files
committed
Fix columns with groupBy
1 parent a7566da commit 3c4d036

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
use Ajax\service\JArray;
1616
use Ajax\service\JString;
1717
use Ajax\semantic\html\base\HtmlSemDoubleElement;
18+
use Ubiquity\utils\base\UArray;
1819

1920
/**
2021
* DataTable widget for displaying list of objects
2122
*
22-
* @version 1.1.1
23+
* @version 1.1.2
2324
* @author jc
2425
* @since 2.2
2526
*
@@ -142,7 +143,7 @@ public function compile(JsUtils $js = NULL, &$view = NULL) {
142143
if ($this->_hasCheckboxes) {
143144
$this->_generateMainCheckbox($captions);
144145
}
145-
$table->setRowCount(0, \sizeof($captions));
146+
$table->setRowCount(0, \count($captions));
146147
$this->_generateHeader($table, $captions);
147148

148149
if (isset($this->_compileParts))
@@ -198,6 +199,10 @@ protected function _hideColumns() {
198199
}
199200

200201
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+
}
201206
$table->setHeaderValues($captions);
202207
if (isset($this->_sortable)) {
203208
$table->setSortable($this->_sortable);
@@ -217,14 +222,15 @@ protected function _generateContent($table) {
217222
return $this->_generateRow($instance, $fields, $table);
218223
});
219224
} 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));
221227
$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) {
223229
$this->_instanceViewer->setInstance($instance);
224230
foreach ($groupByFields as $index => $gbField) {
225231
$this->_generateGroupByRow($index, $gbField, $table, $fields, $activeValues, $uuids);
226232
}
227-
return $this->_generateRow($instance, $fields, $table, null, $uuids);
233+
return $this->_generateRow($instance, $diffFields, $table, null, $uuids);
228234
});
229235
}
230236
if ($table->getRowCount() == 0) {
@@ -287,7 +293,6 @@ protected function _generateRow($instance, $fields, &$table, $checkedClass = nul
287293
$checked = $func($instance);
288294
}
289295
$ck->setChecked($checked);
290-
// $ck->setOnChange("event.stopPropagation();");
291296
$field = $ck->getField();
292297
$field->setProperty("value", $dataAjax);
293298
$field->setProperty("name", "selection[]");
@@ -711,8 +716,8 @@ public function getGroupByFields() {
711716
public function setGroupByFields($_groupByFields) {
712717
$this->_instanceViewer->setGroupByFields($_groupByFields);
713718
}
714-
715-
public function addGroupBy($index){
719+
720+
public function addGroupBy($index) {
716721
$index = $this->_getIndex($index);
717722
if ($index !== false) {
718723
$this->_instanceViewer->addGroupBy($index);

0 commit comments

Comments
 (0)