diff --git a/demos/database.php b/demos/database.php index 8cdc8c656f..bd06bafdad 100644 --- a/demos/database.php +++ b/demos/database.php @@ -26,7 +26,7 @@ public function init() $this->addField('name', ['actual' => 'nicename', 'required' => true, 'type' => 'string']); $this->addField('sys_name', ['actual' => 'name', 'system' => true]); - $this->addField('iso', ['caption' => 'ISO', 'required' => true, 'type' => 'string']); + $this->addField('iso', ['caption' => 'ISO', 'required' => true, 'type' => 'string', 'ui'=>['table'=>['sortable'=>false]]]); $this->addField('iso3', ['caption' => 'ISO3', 'required' => true, 'type' => 'string']); $this->addField('numcode', ['caption' => 'ISO Numeric Code', 'type' => 'number', 'required' => true]); $this->addField('phonecode', ['caption' => 'Phone Prefix', 'type' => 'number', 'required' => true]); diff --git a/docs/grid.rst b/docs/grid.rst index 8518fa64ab..d3c92dbb15 100644 --- a/docs/grid.rst +++ b/docs/grid.rst @@ -167,8 +167,8 @@ Sorting When grid is associated with a model that supports order, it will automatically make itself sortable. You can override this behaviour by setting $sortable property to `true` or `false`. -Additionally you may set list of sortable fields to a sortable property if you wish that your grid would be -sortable only for those columns. +You can also set $sortable property for each table column decorator. That way you can enable/disable sorting +of particular columns. See also :php:attr:`Table::$sortable`. diff --git a/public/agileui.less b/public/agileui.less index 61bd916dca..ab18090682 100644 --- a/public/agileui.less +++ b/public/agileui.less @@ -125,6 +125,10 @@ footer.atk-footer { } } +.ui.sortable.table thead th:not(.sortable) { + cursor: default; +} + // Components .atk-overflow-auto { diff --git a/src/Grid.php b/src/Grid.php index a7b9ca0ea2..4b72a83efe 100644 --- a/src/Grid.php +++ b/src/Grid.php @@ -601,7 +601,7 @@ public function addUserAction(Generic $action) */ public function getSortBy() { - return isset($_GET[$this->sortTrigger]) ? $_GET[$this->sortTrigger] : null; + return $_GET[$this->sortTrigger] ?? null; } /** @@ -639,7 +639,7 @@ public function applySort() $this->table->on( 'click', - 'thead>tr>th', + 'thead>tr>th.sortable', new jsReload($this->container, [$this->sortTrigger => (new jQuery())->data('sort')]) ); } diff --git a/src/TableColumn/Generic.php b/src/TableColumn/Generic.php index ca88752c0f..51681c357e 100644 --- a/src/TableColumn/Generic.php +++ b/src/TableColumn/Generic.php @@ -39,6 +39,13 @@ class Generic */ public $caption = null; + /** + * Is column sortable? + * + * @var boolean + */ + public $sortable = true; + /** * The data-column attribute value for Table th tag. * @@ -309,7 +316,7 @@ public function getHeaderCellHTML(Field $field = null, $value = null) $caption = $this->caption ?: $field->getCaption(); $attr = [ - 'data-column' => $this->columnData + 'data-column' => $this->columnData, ]; $class = 'atk-table-column-header'; @@ -321,9 +328,14 @@ public function getHeaderCellHTML(Field $field = null, $value = null) $caption = [$this->headerActionTag, $caption]; } - // If table is being sorted by THIS column, set the proper class if ($this->table->sortable) { $attr['data-sort'] = $field->short_name; + + if ($this->sortable) { + $attr['class'] = ['sortable']; + } + + // If table is being sorted by THIS column, set the proper class if ($this->table->sort_by === $field->short_name) { $class .= ' sorted '.$this->table->sort_order; diff --git a/src/TableColumn/Password.php b/src/TableColumn/Password.php index 2cacacc8ba..32db7a10e7 100644 --- a/src/TableColumn/Password.php +++ b/src/TableColumn/Password.php @@ -7,6 +7,8 @@ */ class Password extends Generic { + public $sortable = false; + public function getDataCellTemplate(\atk4\data\Field $f = null) { return '***';