From 9bf5821a3bfd1877123e029c0f2509b8310b1b48 Mon Sep 17 00:00:00 2001 From: flynsarmy Date: Sat, 23 Aug 2014 17:35:18 +1000 Subject: [PATCH] Allow complex sortable columns --- modules/backend/widgets/Lists.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index 8c8216b73..a9737455e 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -402,6 +402,16 @@ class Lists extends WidgetBase * Apply sorting */ if ($sortColumn = $this->getSortColumn()) { + // Determine if the column has an sqlSelect + foreach ($this->getListColumns() as $column) { + if ($column->columnName == $sortColumn) { + if ($column->sqlSelect) { + $sortColumn = $column->sqlSelect; + } + break; + } + } + $query->orderBy($sortColumn, $this->sortDirection); } @@ -1042,7 +1052,7 @@ class Lists extends WidgetBase // // Helpers // - + /** * Check if column refers to a relation of the model * @param ListColumn $column List column object