Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

CollectionEngine does not support sorting by multiple columns at the same time #332

Description

@timgws

CollectionEngine currently does not support ordering by multiple columns.

I tried extending the Collection class inside Datatable, and adding a new function (sortByMulti), but never got too far into adding this functionality.

    public function sortByMutli($callback, $fields, $options = SORT_REGULAR, $descending = false)
    {
        $required_keys = array_keys($fields);

        $items = [];

        // First we will loop through the items and get the comparator from a callback
        // function which we were given. Then, we will sort the returned values and
        // and grab the corresponding values for the sorted keys from this array.
        foreach ($this->items as $key => $value) {
            print_r($key);
            $results[$key] = $callback($value, $key);

            foreach($required_keys as $_key) {
                print_r($this->items);
                if (!isset($items[$_key]))
                    $items[$_key] = [];

                $items[$_key][$key] = $results[$key][$_key];
            }
        }

        // Then we need to go through and finally sort all the items by the
        // requested direction.
        $column_sort = ['$results'];
        foreach($fields as $key => $item) {
            print_r($key);
            $column_sort[] = "\$$key";
            $column_sort[] = $this->sortByOrder($direction);
        }


        call_user_func_array('array_multisort', $column_sort);

    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions