laravel-filemanager
laravel-filemanager copied to clipboard
Sort by time default
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"
Maybe we should add a config to set default sort type.
Thanks g0110280, When do you think that the changes will be made?
where in the config file that I can change/modify the sorting, bro?
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;
}
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';
Is there a way I can order by "time DESC" without changing the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php?
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
how to set up sort by time (v2.0.0 2021) by default? last upload position first/top
February 2022, I understand the functionality has not been added yet?