Fixed error with sorting

This commit is contained in:
Jose Gonzalez 2021-03-08 11:20:50 +01:00
parent 0860b6e647
commit 34b7c1003b
1 changed files with 10 additions and 7 deletions

View File

@ -1077,13 +1077,16 @@ var TreeController = {
var rawTree = Object.values(data.tree);
// Sorting tree by description (services.treeview_services.php).
rawTree.sort(function(a, b) {
var x = a.elementDescription.toLowerCase();
var y = b.elementDescription.toLowerCase();
if (x < y) {
return -1;
}
if (x > y) {
return 1;
// Only the services are ordered since only they have the elementDescription property.
if (a.elementDescription && b.elementDescription) {
var x = a.elementDescription.toLowerCase();
var y = b.elementDescription.toLowerCase();
if (x < y) {
return -1;
}
if (x > y) {
return 1;
}
}
return 0;
});