Hi, i’m working on a S3 file explorer with a TreeGrid.
i need to sort the file in this way:
- Folder fist, sorted by name.
- Then files sorted by name.
Any idea on how to use properly the sorting?
Thanks
Hi, i’m working on a S3 file explorer with a TreeGrid.
i need to sort the file in this way:
Any idea on how to use properly the sorting?
Thanks
Giovanni Adobati:
Hi, i’m working on a S3 file explorer with a TreeGrid.i need to sort the file in this way:
- Folder fist, sorted by name.
- Then files sorted by name.
Any idea on how to use properly the sorting?
Thanks
For whom is interested, i solved in this way.
Column<S3File, String> fileNameColumn = addColumn(s3File -> {
String filename = s3File.getName();
filename = filename.substring(filename.lastIndexOf(DELIMITER) + 1);
if (s3File.isDirectory()) {
return VaadinIcons.FOLDER_O.getHtml() + " " + filename;
} else if (s3File.isImage()) {
return VaadinIcons.FILE_PICTURE.getHtml() + " " + filename;
} else {
return VaadinIcons.FILE_O.getHtml() + " " + filename;
}
}, new HtmlRenderer()).setCaption(sa.getI18n("FileName"));
fileNameColumn.setComparator((s3fileA, s3fileB) -> {
if(s3fileA.isDirectory() && s3fileB.isDirectory()) {
return s3fileA.getName().compareToIgnoreCase(s3fileB.getName());
}else if(s3fileA.isDirectory() && !s3fileB.isDirectory()) {
return -1;
}else if(!s3fileA.isDirectory() && !s3fileB.isDirectory()) {
return s3fileA.getName().compareToIgnoreCase(s3fileB.getName());
}else {
return 1;
}
});
setSortOrder(GridSortOrder.asc(fileNameColumn));