Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Order Tags in Ascending Order in AEM 6.4.6


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) {
it = tag.listChildren();
while (it.hasNext()){ // Adding all the values from the iterator to the list
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 !!




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


1 Reply
Level 7
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 -