This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

leocavalcante
leocavalcante

Need some help on sorting a list by a computed value.

I saw that October does the list sort at getRecords():

        /*
         * Apply sorting
         */
        if ($sortColumn = $this->getSortColumn()) {
            if (($column = array_get($this->allColumns, $sortColumn)) && $column->valueFrom) {
                $sortColumn = $this->isColumnPivot($column)
                    ? 'pivot_' . $column->valueFrom
                    : $column->valueFrom;
            }

            $query->orderBy($sortColumn, $this->sortDirection);
        }

I want to be able to sort the Collection using its sort() method so I can call a computed value on the record.

Has anyone archive that before?

leocavalcante
leocavalcante

Unfortunately I wasn't able to archive this without some October hacking. I hope this PR can be merged: https://github.com/octobercms/october/pull/1853

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.