Skip to content
This repository has been 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

Open
timgws opened this issue Sep 9, 2015 · 0 comments
Milestone

Comments

@timgws
Copy link
Collaborator

timgws commented Sep 9, 2015

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);

    }
@timgws timgws added this to the 5.0 milestone Sep 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant