Skip to content

Instantly share code, notes, and snippets.

@arieljannai
Created January 14, 2016 16:15
Show Gist options
  • Save arieljannai/8d73612ecfb1f953bae0 to your computer and use it in GitHub Desktop.
Save arieljannai/8d73612ecfb1f953bae0 to your computer and use it in GitHub Desktop.
// for this purpose we used the icon propery of our tree object to identify that it is a file (a folder doesn't have an icon, it uses the default one)
var customTreeSort = function(a, b) {
if (this.get_node(a).icon === 'jstree-file' && this.get_node(b).icon === 'jstree-file') {
// organize files
return this.get_text(a).localeCompare(this.get_text(b));
} else {
// files before folders
if (this.get_node(a).icon === 'jstree-file') {
return -1;
}
if (this.get_node(b).icon === 'jstree-file') {
return 1;
}
// organize folders
return this.get_text(a).localeCompare(this.get_text(b));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment