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
BedrockMission!

Learn More

View all

Sign in to view all badges

Order Tags in Ascending Order in AEM 6.4.6

Avatar

Avatar
Give Back 5
Employee
sunjot16
Employee

Likes

103 likes

Total Posts

164 posts

Correct Reply

50 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile

Avatar
Give Back 5
Employee
sunjot16
Employee

Likes

103 likes

Total Posts

164 posts

Correct Reply

50 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile
sunjot16
Employee

10-01-2020

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

 

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar
Ignite 5
Level 6
AnkurAhlawat
Level 6

Likes

111 likes

Total Posts

165 posts

Correct Reply

27 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 20
Ignite 10
Ignite 1
View profile

Avatar
Ignite 5
Level 6
AnkurAhlawat
Level 6

Likes

111 likes

Total Posts

165 posts

Correct Reply

27 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 20
Ignite 10
Ignite 1
View profile
AnkurAhlawat
Level 6

16-02-2021

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