diff --git a/modules/backend/formwidgets/DataTable.php b/modules/backend/formwidgets/DataTable.php index b401d9a05..1adf51e20 100644 --- a/modules/backend/formwidgets/DataTable.php +++ b/modules/backend/formwidgets/DataTable.php @@ -14,15 +14,29 @@ use ApplicationException; */ class DataTable extends FormWidgetBase { - /** - * {@inheritDoc} - */ - protected $defaultAlias = 'datatable'; + // + // Configurable properties + // /** * @var string Table size */ - protected $size = 'large'; + public $size = 'large'; + + /** + * @var bool Allow rows to be sorted + * @todo Not implemented... + */ + public $rowSorting = false; + + // + // Object properties + // + + /** + * {@inheritDoc} + */ + protected $defaultAlias = 'datatable'; /** * @var Backend\Widgets\Table Table widget @@ -34,7 +48,11 @@ class DataTable extends FormWidgetBase */ public function init() { - $this->size = $this->getConfig('size', $this->size); + $this->fillFromConfig([ + 'size', + 'rowSorting', + ]); + $this->table = $this->makeTableWidget(); $this->table->bindToController(); } @@ -64,6 +82,23 @@ class DataTable extends FormWidgetBase $this->populateTableWidget(); $this->vars['table'] = $this->table; $this->vars['size'] = $this->size; + $this->vars['rowSorting'] = $this->rowSorting; + } + + /** + * {@inheritDoc} + */ + public function getLoadValue() + { + $value = (array) parent::getLoadValue(); + + // Sync the array keys as the ID to make the + // table widget happy! + foreach ($value as $key => $_value) { + $value[$key] = ['id' => $key] + (array) $_value; + } + + return $value; } /** @@ -82,6 +117,12 @@ class DataTable extends FormWidgetBase $result += $records; } + // We should be dealing with a simple array, so + // strip out the id columns in the final array. + foreach ($result as $key => $_result) { + unset($result[$key]['id']); + } + return $result; } diff --git a/modules/backend/formwidgets/RecordFinder.php b/modules/backend/formwidgets/RecordFinder.php index 889e0cf9f..6be00aa49 100644 --- a/modules/backend/formwidgets/RecordFinder.php +++ b/modules/backend/formwidgets/RecordFinder.php @@ -101,11 +101,11 @@ class RecordFinder extends FormWidgetBase } /** - * Returns the value as a relation object from the model, + * Returns the model of a relation type, * supports nesting via HTML array. * @return Relation */ - protected function getRelationObject() + protected function getRelationModel() { list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom); @@ -116,17 +116,6 @@ class RecordFinder extends FormWidgetBase ])); } - return $model->{$attribute}(); - } - - /** - * Returns the model of a relation type, - * supports nesting via HTML array. - * @return Relation - */ - protected function getRelationModel() - { - list($model, $attribute) = $this->resolveModelAttribute($this->valueFrom); return $model->makeRelation($attribute); } diff --git a/modules/backend/widgets/table/assets/js/table.js b/modules/backend/widgets/table/assets/js/table.js index 89c200ab8..687af3c4b 100644 --- a/modules/backend/widgets/table/assets/js/table.js +++ b/modules/backend/widgets/table/assets/js/table.js @@ -353,9 +353,9 @@ dataContainer.setAttribute('type', 'hidden') dataContainer.setAttribute('data-container', 'data-container') - dataContainer.value = records[i][columnName] !== undefined ? - records[i][columnName] : - "" + dataContainer.value = records[i][columnName] !== undefined + ? records[i][columnName] + : "" cellContentContainer.setAttribute('class', 'content-container') @@ -391,9 +391,10 @@ Table.prototype.fetchRecords = function(onSuccess) { this.dataSource.getRecords( - this.navigation.getPageFirstRowOffset(), + this.navigation.getPageFirstRowOffset(), this.options.recordsPerPage, - onSuccess) + onSuccess + ) } Table.prototype.updateScrollbar = function() {