Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Custom Media Library Transformations: Default Sorting of Media Library Content View modes: 
User avatar
Member
Member
Greg - 7/20/2010 2:07:25 PM
   
Custom Media Library Transformations: Default Sorting of Media Library Content
I inherited a custom media library transformation that my department uses for displaying various forms that are stored in a media library.

http://www.cityofbonitaspringscd.org/Forms.aspx

The forms are categorized by type and are by default sorted by the date they are added to the media library. Users have the option to sort each form category by Name, Date, and Size but I would like to sort the forms alphabetically by default within each category.

I tried to research an online solution first, and still can't find a setting, property, or piece of code to specify the default sort order for media library content. To further complicate matters, I am a CMS, HTML, and CSS novice.

Any suggestions?

Custom Media Library Transformation
<%@ Register Src="~/CMSModules/MediaLibrary/Controls/LiveControls/MediaFilePreview.ascx" TagName="MediaFilePreview" TagPrefix="cc1" %>

<div class="form">
<h3>
<a href="<%# HTMLHelper.HTMLEncode(MediaLibraryFunctions.GetMediaFileUrl(Eval("FileLibraryID") ,Eval("FilePath"), Eval("FileGUID"), Eval("FileName"), GetDataControlValue<bool>("UseSecureLinks"), false)) %>" target="_blank">
<%# HTMLEncode(GetNotEmpty("FileTitle")) %>
<br/>
<%# HTMLEncode(GetNotEmpty("FileDescription")) %></a>
</h3>

<p>
<span>Type:</span> <%# Eval("FileExtension", true) %>
<span>Size:</span> <%# DataHelper.GetSizeString(ValidationHelper.GetLong(Eval("FileSize"), 0)) %>
<span>Uploaded:</span> <%# ((DateTime)Eval("FileCreatedWhen")).ToString("M/d/yyyy") %>
</p>
</div>


Thanks in advance,
Greg Smith

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 8/4/2010 4:28:31 PM
   
RE:Custom Media Library Transformations: Default Sorting of Media Library Content
Hello,

Basically, the default sorting of items within Media Gallery webpart is done in following file:

~\CMSModules\MediaLibrary\Controls\Filters\MediaLibrarySort.ascx.cs

In order to achieve default sorting, you will need to adjust OrderBy property on the line 118. Please find following statement:


this.OrderBy = QueryHelper.GetString(this.SortQueryStringKey, "").Replace(";", " ");


and change it this way:

this.OrderBy = QueryHelper.GetString(this.SortQueryStringKey, "Filename ASC").Replace(";", " ");


It adds default value to the OrderBy condition if no sort query string exists.

Best regards
Ondrej Vasil

User avatar
Member
Member
Greg - 8/5/2010 9:24:29 AM
   
RE:Custom Media Library Transformations: Default Sorting of Media Library Content
Thank you very much for the suggestion.

In the event that the site architect does not want to modify the CMS module code, is there another option that may be specific to that Media Gallery's web part properties?

Perhaps through a macro in the Web part properties (media gallery) Filter Settings "Sort Direction Querystring Key" value?

User avatar
Member
Member
Greg - 8/9/2010 4:16:47 PM
   
RE:Custom Media Library Transformations: Default Sorting of Media Library Content
Please disregard my previous post. I would like to start a new thread for that topic since you answered my original question.

Thanks,
Greg

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 8/20/2010 4:36:25 AM
   
RE:Custom Media Library Transformations: Default Sorting of Media Library Content
Hi Greg,

No problem, we can discuss it here, since it's pretty related topic. The thing is, Media Gallery webpart (not even Media Filter) doesn't have any kind of default sorting value. In another words, there is no other way than manually overwrite that webpart file. Due to upgrade issues, I would recommend you clone this webpart: http://devnet.kentico.com/docs/devguide/modifying_the_code_of_standard_web_parts.htm.

Anyway, I'm passing that as a requirement for further versions of Kentico CMS to our product manager. It seems to be quite basic change, so I believe it could be added within version 6.0.

Best regards
Ondrej Vasil

User avatar
Member
Member
merete-grape - 3/29/2012 6:56:11 AM
   
RE:Custom Media Library Transformations: Default Sorting of Media Library Content
Can't find this code in my file....

use v5.5.4311 R2

User avatar
Kentico Support
Kentico Support
kentico_janh - 3/30/2012 6:44:51 AM
   
RE:Custom Media Library Transformations: Default Sorting of Media Library Content
Hello,

Are you editing the right file (~\CMSModules\MediaLibrary\Controls\Filters\MediaLibrarySort.ascx.cs)? The code is on the line 126 and you can change it to:

string[] orderBy = QueryHelper.GetString(this.SortQueryStringKey, "FileName;ASC").Split(';');


Best regards,
Jan Hermann

User avatar
Member
Member
merete-grape - 4/12/2012 3:45:21 PM
   
RE:Custom Media Library Transformations: Default Sorting of Media Library Content
Found it!
Thx a lot!

Best regards,
Merete