Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort by time default #337

Open
josearagon opened this issue Jun 6, 2017 · 9 comments
Open

Sort by time default #337

josearagon opened this issue Jun 6, 2017 · 9 comments
Labels
enhancement Optimization for existing features.

Comments

@josearagon
Copy link

josearagon commented Jun 6, 2017

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"

@streamtw streamtw added enhancement Optimization for existing features. question Already has a solution. No further action is required. and removed enhancement Optimization for existing features. labels Jun 7, 2017
@streamtw
Copy link
Member

streamtw commented Jun 7, 2017

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

@streamtw streamtw added enhancement Optimization for existing features. and removed question Already has a solution. No further action is required. labels Jun 7, 2017
@josearagon
Copy link
Author

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

@nalorim
Copy link

nalorim commented Oct 9, 2017

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

@anasmorahhib
Copy link

anasmorahhib commented Oct 29, 2017

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

@josearagon
Copy link
Author

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

@arbexmb
Copy link

arbexmb commented Apr 26, 2019

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

@3s777
Copy link

3s777 commented Mar 27, 2020

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

@masumbillahbd
Copy link

masumbillahbd commented Aug 21, 2021

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

@Ercogx
Copy link

Ercogx commented Feb 12, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Optimization for existing features.
Projects
None yet
Development

No branches or pull requests

8 participants