Friday, September 26, 2014

Sorting SharePoint list item attachments in alphabetical order (Fixed)


Note: Please read the complete article and notice the changes. It 100% worked for me.

SharePoint 2007 provides an OOTB facility to sort list item attachments in alphabetical order while SharePoint 2010 don't. I have googled around for many days but could not find any OOTB feature that can help me out to do so. So i decided to go with custom JS code. I found the article by Sopholos and it was the main turning point for me.

Here is the final result of my list item.




I copied the code as per on his article (in Russian) and pasted in my v4.master page. Believe me absolutely nothing happened :o) . I dug  into it and used my programming skills and found that i was not using the code at the right place. I moved the code from top of the page to its bottom, used alerts to check if the code is running or not. Final screenshot below...


1. Download the JS file from below URL
2.Copy the file into the directory below
c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\
3. Copy the below code in your v4.Master file using SP Designer 
<SharePoint:ScriptLink language="javascript" name="TSorter_1.js" OnDemand="false" runat="server"/>
<script type="text/javascript">
function init()
{
var table = document.getElementById("idAttachmentsTable");
if (!table)
   RETURN;
var thead = document.createElement("thead");
var trow = document.createElement("tr");
var column = document.createElement("TH");
column.abbr = "link_column";
column.innerHTML = '<a href="#"></a>';
table.appendChild(thead);
thead.appendChild(trow);
trow.appendChild(column);
var Table1Sorter = new TSorter;
Table1Sorter.init('idAttachmentsTable');
Table1Sorter.doSort(column);
Table1Sorter.doSort(column);
}
init();
</script>

4. Save the master page, Check In and publish it. You are done.

Regards,

No comments:

Post a Comment