Need to sort tags alphabetically. | Community
Skip to main content
ranadyutis95334
Level 3
Jan 14, 2016 8:35 AM UTC
Solved

Need to sort tags alphabetically.

There are 8 categories of tags that are included in the document library, which all correspond to tags in AEM. The child tags of those categories are displayed when you click the arrow on each category.

 

 

Apparently, these child tags are just shown in the order they appear in the JCR.  Is there a way to sort the child tags  in alphabetical order

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Jan 14, 2016 12:13 PM UTC

Write a OSGI service to do this sorting.

There is one more approach you can try for:

Add a beforesubmit listener in your dialog box and before data gets saved in JCR, sort it with JS

12 replies

kautuk_sahni
Employee
Jan 14, 2016 9:44 AM UTC

Hi

Adding to what Praveen mentioned, there is no such OOTB to get sorted tags alphabetically.

But, there is a community article covering this,

Link:- http://experience-aem.blogspot.in/2014/12/aem-6-sp1-touch-ui-sort-and-show-tags-in-alphabetical-order.html

// Sort the tags alphabetically in Asset Metadata Editor of Touch UI

Solution


1) Login to CRXDE Lite (http://localhost:4502/crx/de) and create folder /apps/sort-metadata-editor-tags

2 Create node /apps/sort-metadata-editor-tags/clientlib of type cq:ClientLibraryFolder and add a String property categories with value dam.gui.metadataeditor

3) Create file (nt:file) /apps/sort-metadata-editor-tags/clientlib/js.txt and add

                      sort-tags.js

4) Create file (nt:file) /apps/sort-metadata-editor-tags/clientlib/sort-tags.js and add the following code.
 

     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$(document).on('cui-contentloaded.data-api', function (e) {
    var $tagsWidget = $('[data-metaType=tags]');
    var $selectList = $tagsWidget.find('.js-coral-Autocomplete-selectList');
 
    $selectList.html($selectList.find("li").sort(function(a, b) {
        a = $(a).text();
        b = $(b).text();
 
        //this piece was copied from underscore.js sortBy
        if (a > b || a === void 0){
            return 1;
        }else if (a < b || b === void 0){
            return -1;
        }
 
        return 1;
    }));
});
 

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Translate
Kautuk Sahni
edubey
Level 10
Jan 14, 2016 8:44 AM UTC

I don't see any OOTB feature to implement this. will check is there is any...

What you can do is to override default behavior implement your custom one. There are few example available here

http://experience-aem.blogspot.in/2014/12/aem-6-sp1-touch-ui-sort-and-show-tags-in-alphabetical-order.html

http://experience-aem.blogspot.in/2015/02/aem-6-sp2-classic-ui-tags-widget-show-sub-folders-as-namespaces.html

Translate