Jump to content

Topic on Extension talk:PageAttachment

Sorting PageAttachments by Title

2
198.29.191.149 (talkcontribs)

The following code should be added to page-attachment.js in order to sort by document title:

   function sortData(){
            var tableData = document.getElementById('PageAttachment').getElementsByTagName('tbody').item(0);
            var rowData = tableData.getElementsByTagName('tr');            
            for(var i = 0; i < rowData.length - 1; i++){
                for(var j = 0; j < rowData.length - (i + 1); j++){
			var first = (rowData.item(j).getElementsByTagName('td').item(0).innerHTML.toString());
		        var last = (rowData.item(j+1).getElementsByTagName('td').item(0).innerHTML.toString());
                            if( first > last){
                        tableData.insertBefore(rowData.item(j+1),rowData.item(j));
                    }
                }
            }
        }

Along with this function, add the call to it:

sortData();

to pageAttachment_renderAttachmentSection(html). It should look like this:

function pageAttachment_renderAttachmentSection(html)
{
   var e = document.getElementById('PageAttachment');
   e.innerHTML = html;
   sortData();
}
Aldrin (talkcontribs)

You or someone else have already created an enhancement request to add "sort" option (Issue# 78). I'll work on this after moving the code to Github as Google Code is shutting down.

Reply to "Sorting PageAttachments by Title"