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

laurent1050
Champ in-the-making
Champ in-the-making
Thanks Loftux for this info.

I don't want to directly modify tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/filters.lib.js. I'd prefer to copy this file in the shared directory of Tomcat.

Where in the shared directory must I copy the file filter.lib.js to override the normal one ?

Thanks
Laurent

loftux
Star Contributor
Star Contributor
In file web-scripts-application-context.xml you will find the beans for the classpath locations for webscripts. The default is alfresco/templates/webscripts, there is also one defined for alfresco/extension/templates/webscripts. Try placing your overrides there (having the same full path).
I'm not sure however that you can override only a single file, or if the extension path is read last (it doesn't look like that in the bean definition). I always do amps of my customizations, so this is really not an issue for me, and thus haven't tested.

laurent1050
Champ in-the-making
Champ in-the-making
Thanks for your quick answer.

I've tried to put filters.lib.js in
    tomcat\shared\classes\alfresco\extension\templates\webscripts\org\alfresco\slingshot\documentlibrary
    tomcat\shared\classes\alfresco\templates\webscripts\org\alfresco\slingshot\documentlibrary
But nothing happens.

It only works if I put the file in
    tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary
Any ideas ?

Laurent

loftux
Star Contributor
Star Contributor
Since this is an include file (used as a lib for other webscripts), you may have to override those files as well, and possibly the entire webscript, all the files that make up the webscript.

laurent1050
Champ in-the-making
Champ in-the-making
Nothing new if I had all the files from tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary to tomcat\shared\classes\alfresco\extension\templates\webscripts\org\alfresco\slingshot\documentlibrary or tomcat\shared\classes\alfresco\templates\webscripts\org\alfresco\slingshot\documentlibrary.

I've also tried to modify doclist.get.json.ftl, adding ?sort_by("displayName")


"items":
   [
      <#list doclist.items?sort_by("displayName") as item>
      {
         <@itemLib.itemJSON item=item />
      }<#if item_has_next>,</#if>
      </#list>
   ]

But no sort of the folders…

loftux
Star Contributor
Star Contributor
Since you are trying to use a freemarker sort, did the sort not work for you when edited filters.lib.js in its original location?

For Alfresco webscripts it seems like there is no easy override unless you start fiddling with bean definitions. For Surf (Share), this is built in and you can do exactly this (putting overrides in web-extension).
Maybe start a separate topic on the subject so it gets noticed if someone knows how to do it in Alfresco.

laurent1050
Champ in-the-making
Champ in-the-making
The sort made in filters.lib.js works well. I just don't know where to put the file in shared.
But I'm discovering Alfresco and testing different solutions  :wink:

Thank for your answers, I'll continue testing, and will start a new thread if needed.

croc
Champ in-the-making
Champ in-the-making
Hi guys,

Is the anyway I can do this "on the fly". Like adding a drop-downlist and list the values, then I want it to get sorted automatically based on the value selected from the drop-downlist.
I am using version 3.3.1

Thanks,
Croc

bbukvic
Champ in-the-making
Champ in-the-making
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