Back

Sorting by Number then Alpha on File Repository listing

Description

The File Repository Listing provides a vtl override that you can use to display your sorted files. In order to get it to arrange by number first (descending) and then alpha second (ascending).  I did a pull sorted, then split into two arrays the results based upon the first letter of the folder or file title. Here is the code that shows how to split into the arrays, and then iterate through them to display in the proper sort order.

 

Link: http://www.uakron.edu/bot/board-memos.dot

Code

## Sort by Number then Alpha
<table border="0" cellpadding="3"  cellspacing="1" width="90%" class="fileRepositoryTable" summary="$!tableSummary" >
<thead>
<tr>
    <th class="imgColumn" align="right">
        #if($hasParent)
            <a href="?folderPath=$fileRepository_upFolder"><img  align="absbottom" src="/html/images/icons/arrow-curve-090.png" border="0" alt="up a folder"></a>
        #end
    </th>
    <th class="nameColumn">&nbsp;<strong>Name</strong></th>
    <th class="sizeColumn">&nbsp;<strong>Size</strong></th>

</tr>
</thead>
<tbody>
#set($alphafiles = $contents.getEmptyList())
#set($numfiles = $contents.getEmptyList())
#set($even = false)
#set($files = $sorter.sort($fileRepository_foldersList, "title:desc"))
#foreach($file in $files)
  #if($file.name.substring(0,1).matches("[a-zA-Z]"))
  #set($_dummy = $alphafiles.add($file))
#else
  #set($dummy = $numfiles.add($file))
#end
#end
#foreach($folder in $numfiles)
<tr class="#if($even)even#{else}alt#end" >
    <td align="right" valign="top"><a href="?folderPath=${folder.getPath()}"><img src="/html/images/icons/folder-horizontal.png" alt="folder"></a></td>

    <td><a href="?folderPath=${folder.getPath()}">$folder.name</a>
        <div style="padding-left:10px;">
            $!folder.title
        </div>
    </td>
    <td>&nbsp;</td>

</tr>
	#set($even = !$even)
#end

#foreach($folder in $alphafiles)
<tr class="#if($even)even#{else}alt#end" >
    <td align="right" valign="top"><a href="?folderPath=${folder.getPath()}"><img src="/html/images/icons/folder-horizontal.png" alt="folder"></a></td>

    <td><a href="?folderPath=${folder.getPath()}">$folder.name</a>
        <div style="padding-left:10px;">
            $!folder.title
        </div>
    </td>
    <td>&nbsp;</td>

</tr>
	#set($even = !$even)
#end



#foreach($file in $sorter.sort($fileRepository_filesList, "fileName:desc"))
<tr class="#if($even)even#{else}alt#end">
    <td align="center" valign="top"><a href="$fileRepository_showFolder$file.fileName"><img src="/icon?i=${file.getExtension()}" width="16" height="16" alt="${file.getExtension()} file"></a></td>
    <td valign="top">
        <a href="$fileRepository_showFolder$file.fileName">$file.fileName</a>
        <div style="padding-left:10px;">
            $!file.friendlyName
        </div>


    </td>
    <td valign="top">$math.add($math.ceil($math.div(${file.size}, 1024)), 1) kb</td>
</tr>
	#set($even = !$even)

#end
</tbody>
</table>