RE: Configure default sort order for Documents & Media portlet

thumbnail
André Bräkling, modified 5 Years ago. Junior Member Posts: 30 Join Date: 7/8/13 Recent Posts
Hi everbody.

We are using the Documents & Media portlet to offer  a file space to our users.

By default, the portlet orders by "Modified date", but we want to change this default setting to "Order By: Title".I had a look at the portlet configuration, the control panel configuration, etc. but I don't see where to change this setting.

Maybe I'm missing something... can anybody please give me a hint?

Thanks in advance!

André
thumbnail
Mohammed Yasin, modified 5 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi ,You can try setting the portal preference with orderByCol ,  
  PortalPreferences portalPreferences =  PortletPreferencesFactoryUtil.getPortalPreferences(request);
   portalPreferences.setValue("com_liferay_document_library_web_portlet_DLPortlet", "order-by-col", "title");
    portalPreferences.setValue("com_liferay_document_library_web_portlet_DLPortlet", "order-by-type", "asc");

thumbnail
André Bräkling, modified 5 Years ago. Junior Member Posts: 30 Join Date: 7/8/13 Recent Posts
Thanks for your replay. I added the preferences to my portal-ext.properties (if possible, I want to avoid programmatical changes for this issue):
com_liferay_document_library_web_portlet_DLPortlet.order-by-col=title
com_liferay_document_library_web_portlet_DLPortlet.order-by-type=asc
After restarting, they appear in my Portal Properties (Server Administration -> Properties -> Portal Properties), but by default the Documents & Media still sorts by modified date. Am I missing something?
thumbnail
Mohammed Yasin, modified 5 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi
i dont think its will work adding in portal-ext.properties , it needs to added  to database from below api.
 PortalPreferences portalPreferences =  PortletPreferencesFactoryUtil.getPortalPreferences(request);
   portalPreferences.setValue("com_liferay_document_library_web_portlet_DLPortlet", "order-by-col", "title");
    portalPreferences.setValue("com_liferay_document_library_web_portlet_DLPortlet", "order-by-type", "asc");
thumbnail
André Bräkling, modified 5 Years ago. Junior Member Posts: 30 Join Date: 7/8/13 Recent Posts
You're right, I ran it as a Groovy script and this did the trick:
import com.liferay.portlet.PortalPreferencesImpl;
import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil;
PortalPreferencesImpl portalPreferences =  PortletPreferencesFactoryUtil.getPortalPreferences([i]--USER_ID--[/i], true);
portalPreferences.setValue("com_liferay_document_library_web_portlet_DLPortlet", "order-by-col", "title");
portalPreferences.setValue("com_liferay_document_library_web_portlet_DLPortlet", "order-by-type", "asc");
Thanks a lot!I just wonder why there is no way to configure this in the portlet configuration, the admin panel or at least via config file. I'll ask for a Jira account and write a feature request here.
Aamjad Pinjari, modified 5 Years ago. New Member Posts: 2 Join Date: 1/30/20 Recent Posts
Hiii,you did it for particular user but i want to do it for all users in my portal can you suggest me a way to do itthanks.
thumbnail
Mohammed Yasin, modified 5 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi ,
i think same code should  apply to all user . as it might be apply preference to portal
Aamjad Pinjari, modified 5 Years ago. New Member Posts: 2 Join Date: 1/30/20 Recent Posts
thanks for reply,but it's not applying for all users it's only applying for admin only.
thanks