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

Already on GitHub? Sign in to your account

getfolder sorting issue #105

Closed
claudep opened this Issue Mar 28, 2012 · 3 comments

Comments

Projects
None yet
4 participants
Contributor

claudep commented Mar 28, 2012

The documentation explains that getfolder returns an array of file and folder objects, and that folders should always be returned before files. The example does not show a real array, but an object with paths as keys. The problem is that object keys are not guaranteed to be sorted by the JSON spec (see http://json.org/: An object is an unordered set of name/value pairs.), even if many implementation do keep the sort order.

So either:

  1. getfolder returns an array of sorted folders and files [ {...], ...]
  2. keep getfolder output as object with paths as keys, and sort files and folders in filemanager.js.

It depends on where you'd like to sort objects, client-side or server-side.

Owner

simogeo commented Mar 28, 2012

Actually, there is no special need to return folders before files. This is a documentation outdated mention.

Nowadays, the content is returned (by the server - PHP Connector) in alphabetical order. But it would be great, indeed, to keep that alphabetical order and display folders first.

I agree with author. It can be done by option (elfinder do it in this way).

SManAT commented May 18, 2013

Sorting is easy:
I Have made a new class that extends Filemanager. Also tha i can update my databases via ajax calls if e.g. a file is renamed etc.

within the getfolder() function i'm doing sorting like this
$a = array();$b = array();
foreach ($data as $key=>$item){
if(strcmp($item["File Type"], "dir")==0){
$a[$key]=$item;
}else{
$b[$key]=$item;
}
}
return array_merge($a,$b);

That provides Directorys first, then the files both in alphabeticaly order.

Tried also to implement a plugin, but wasnt working. Let me know if i can support this very COOL project!

simogeo added a commit that referenced this issue May 20, 2013

sorting options on configuration file (fixing issue #105), adding
"filemtime" attributes to returned JSON data
Owner

simogeo commented May 20, 2013

@SManAT : thanks for your piece of code, sorting is now part of configuration option, see the following wiki page : https://github.com/simogeo/Filemanager/wiki/How-to-change-files-and-folders-order-in-list%3F and the latest commit : a273af0.

If you want to contribute to the FileManager, you're very welcome : ideas, code, https://github.com/simogeo/Filemanager/wiki, bug fixes/evolution, .... FM is just waiting for you!

@simogeo simogeo closed this May 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment