Datatable icon indicating copy to clipboard operation
Datatable copied to clipboard

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

Open timgws opened this issue 10 years ago • 0 comments

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 avatar Sep 09 '15 05:09 timgws