cancel
Showing results for 
Search instead for 
Did you mean: 

How to sort on name in Document Library or javascript

loftux
Star Contributor
Star Contributor
This is how you can sort on document name in Alfresco Share Document Library. If you like me don't like the semi-random listing  :?
Locate tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js
For the filters you would like sorted, sample for default/path filter

         default: // "path"
            filterParams.variablePath = false;
            filterQuery = "+PATH:\"" + parsedArgs.pathNode.qnamePath + "/*\"";
            filterParams.query = filterQuery + filterQueryDefaults;
            //Adding sort parameters
            filterParams.sort = [
                                {
                                      column: "@{http://www.alfresco.org/model/content/1.0}name",
                                      ascending: true
                               },
                                {
                                   column: "@{http://www.alfresco.org/model/content/1.0}modified",
                                   ascending: false
                                }
                               ];
            break;
The important step here is that sorting on name only works if you add one additional sort field. If you only add cm:name for sort, it is just ignored. I think (haven't tested yet) this is applicable to other javascript searches where you need to do search on fields that are multilingual and/or tokenized. I'm not sure what is the cause that only name sort fails, the issue has been reported several times in Jira, so I do not add a new issue there, but added a comment to http://issues.alfresco.com/jira/browse/ALF-4664.
12 REPLIES 12

mikeh
Star Contributor
Star Contributor
Hello

Is anyone making "sort on the fly" functionality?
If someone did, and if that 'somebody' want to share with ordinary dummy users  Smiley Very Happy , we  (ordinary dummy users Smiley Very Happy) would be very grateful if we can see a description of the proceedings and all the necessary steps …

Thank you in advance
It's already all on HEAD (i.e. it's available as part of Team and has since been merged to Community). It will be product when v4.0 is released in a couple of months or so or you can grab the code now and have a go at porting it back to v3.3 or v3.4.

Thanks,
Mike

bbukvic
Champ in-the-making
Champ in-the-making
Thank you for information.

kwilliamsjr
Champ in-the-making
Champ in-the-making
fyi I got it to work by modifying the filters.lib.js. I also modified filter.get.config.xml and filter.get.properties with the case I defined and relevant definitions. anyway for what it's worth here is what works:

         case "datesort":
            var argMax = args.max;
            filterQuery = "+PATH:\"" + parsedArgs.rootNode.qnamePath + "//*\"";
            filterQuery += " +TYPE:\"content\"";

            filterParams.sort = [
             {
                column: "@cm:" + dateField,
                ascending: false
             }];
           filterParams.query = filterQuery;
           break;

one question though… I modified the deployed file (only filters.lib.js) and I'd prefer to build that out in my build tree. can someone explain how I can do that as it exits in alfresco and not share so I can deploy it properly? I'm a little confused on the build structure… I have it working for share, I would just like to get it working for alfresco.

Mike?