laravel-filemanager icon indicating copy to clipboard operation
laravel-filemanager copied to clipboard

Sort by time default

Open josearagon opened this issue 7 years ago • 9 comments

I need load files order by "time DESC" when the iframe of laravel-filemanager is called. Is posible? I read the code and see that we cant order by time DESC and the code dont have options to configure a default "sort_type"

josearagon avatar Jun 06 '17 13:06 josearagon

Maybe we should add a config to set default sort type.

streamtw avatar Jun 07 '17 03:06 streamtw

Thanks g0110280, When do you think that the changes will be made?

josearagon avatar Jun 07 '17 06:06 josearagon

where in the config file that I can change/modify the sorting, bro?

nalorim avatar Oct 09 '17 09:10 nalorim

To load files order by "time DESC" you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php

   public function sortFilesAndDirectories($arr_items, $sort_type)
    {
        if ($sort_type == 'time') {
            $key_to_sort = 'updated';
        } elseif ($sort_type == 'alphabetic') {
            $key_to_sort = 'name';
        } else {
            $key_to_sort = 'updated';
        }

 
           return strcmp($a->{$key_to_sort}, $b->{$key_to_sort});
        });

        return $arr_items;
    }

with

   public function sortFilesAndDirectories($arr_items, $sort_type)
    {
        if ($sort_type == 'time') {
            $key_to_sort = 'updated';
        } elseif ($sort_type == 'alphabetic') {
            $key_to_sort = 'name';
        } else {
            $key_to_sort = 'updated';
        }

        uasort($arr_items, function ($a, $b) use ($key_to_sort) {
            if ( $a->$key_to_sort == $b->$key_to_sort )
                return 0;
            else if ( $a->$key_to_sort > $b->$key_to_sort)
                return -1;
            else
                return 1;
        });

        return $arr_items;
    }

anasmorahhib avatar Oct 29 '17 23:10 anasmorahhib

Thanks @anasmorahhib, your code help me a lot, but I also need to change the default sort_type var in vendor/unisharp/laravel-filemanager/public/js/script.js I have replaced this line: var sort_type = 'alphabetic'; for this: var sort_type = 'updated';

josearagon avatar Dec 30 '17 09:12 josearagon

Is there a way I can order by "time DESC" without changing the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php?

arbexmb avatar Apr 26 '19 13:04 arbexmb

This is my solution File Vendor/Unisharp/laravel-filemanager/public/js/script.js row 3 instead var sort_type = 'alphabetic'; var sort_type = 'time';

File Vendor/Unisharp/laravel-filemanager/src/Controllers/ItemsController.php instead 'items' => array_map(function ($item) { return $item->fill()->attributes; }, array_merge($this->lfm->folders(), $this->lfm->files())), change to 'items' => array_map(function ($item) { return $item->fill()->attributes; }, array_merge($this->lfm->folders(), array_reverse($this->lfm->files()))),

Sorry for my english

3s777 avatar Mar 27 '20 11:03 3s777

how to set up sort by time (v2.0.0 2021) by default? last upload position first/top

masumbillahbd avatar Aug 21 '21 06:08 masumbillahbd

February 2022, I understand the functionality has not been added yet?

Ercogx avatar Feb 12 '22 21:02 Ercogx