Expand my Community achievements bar.

SOLVED

Order Tags in Ascending Order in AEM 6.4.6

Avatar

Employee

Hey Everyone,

I just wanted to share something regarding ordering the AEM Tags under Tagging console (Touch UI) in ascending order.

There isn't any OOTB way to do it. However, I tried something and it worked. The solution may not be the most optimal one, but it works.

-------------
Steps to Do:
-------------
1) Overlay /libs/cq/tagging/gui/components/admin/endor/datasources/tagsdatasource/tagsdatasource.jsp
in /apps/cq/tagging/gui/components/admin/endor/datasources/tagsdatasource/tagsdatasource.jsp and then make the changes to the apps' tagsdatasource.jsp file accordingly.


2) Code Sample: Added the lines that have comments on their right.
---------------------------------------------------------------------------------------------
TagManager tagMgr = resourceResolver.adaptTo(TagManager.class);
String suffix = slingRequest.getRequestPathInfo().getSuffix();
Iterator<Tag> it;
List<Tag> listTag = new ArrayList<Tag>(); // Initializing a new List of type Tag.
if (suffix == null) {
it = tagMgr.getNamespacesIter();
} else {
Tag tag = tagMgr.resolve(suffix);
if (tag == null) {
return;
}
it = tag.listChildren();
while (it.hasNext()){ // Adding all the values from the iterator to the list
listTag.add(it.next());
}
listTag.sort((l1,l2)-> l1.getTitle().compareTo(l2.getTitle())); // Sorting the list in ascending order of the title.
it = listTag.iterator(); // Returning the iterator of the sorted list

}


Config cfg = new Config(resource);
Config dsCfg = new Config(resource.getChild(Config.DATASOURCE));
String filters[] = dsCfg.get("filters", String[].class);

---------------------------
---------------------------
Once you make the changes, please recompile JSPs & rebuild clientlibs [1] (via file system) , if the changes don't get reflected.

You should get all the tags in ascending order.


You can also refer to [2] for Tag API documentation:


Hope it works the same way for you too !!


[1] https://helpx.adobe.com/ca/experience-manager/kb/How-to-force-a-recompilation-of-all-Sling-scripts-j...

[2] https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/co...

 

Tags sorted in Ascending Order in AEM 6.4.6Tags sorted in Ascending Order in AEM 6.4.6

 

1 Accepted Solution

Avatar

Correct answer by
Level 7

Thanks for sharing the information sunjot, but it will work only if your tag list is small. As it is a server side paginated call with offset of 40 records at a time. Which means if you have more than 40 tags under one category then only first 40 will be sorted, and when the user scrolls then next call will go from 40-80 which will be totally separate set of records and again this will be sorted alphabetically.  

 

You also need to update the limit from 40 to your desired number.

 

See below example -

 

http://localhost:4502/libs/cq/tagging/gui/content/tags/jcr:content/views/column.40.40.html/content/cq:tags/default?_=1613533675521

View solution in original post

1 Reply

Avatar

Correct answer by
Level 7

Thanks for sharing the information sunjot, but it will work only if your tag list is small. As it is a server side paginated call with offset of 40 records at a time. Which means if you have more than 40 tags under one category then only first 40 will be sorted, and when the user scrolls then next call will go from 40-80 which will be totally separate set of records and again this will be sorted alphabetically.  

 

You also need to update the limit from 40 to your desired number.

 

See below example -

 

http://localhost:4502/libs/cq/tagging/gui/content/tags/jcr:content/views/column.40.40.html/content/cq:tags/default?_=1613533675521