Search DominoPower's 11,441 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
Sorting your Domino views with JavaScript (continued)

contents[0].booktitle = HARRY POTTER AND THE GOBLET OF FIRE
contents[0].author = JK ROWLING
contents[0].row = <tr title="row"><td title="booktitle" abbr="HARRY POTTER AND THE GOBLET OF FIRE" width="50%"><a href="/sort/0/23D990F27D759CD5CC25709800016FFF?OpenDocument">Harry Potter and the Goblet of Fire</a></td>
<td title="author" abbr="JK ROWLING" width="50%">JK Rowling</td>
</tr>

So each entry in the "contents" array consists of two sortable keys and the HTML to output for each row. Finally I added the sort routines themselves to the JS Header section.

var contents = new Array();

// Returns array of table elements, eg: Get all "td" elements where "title" attribute is "booktitle".
function getTableElements(tagName, attrName, attrValue) {
var sourceElements;
var targetElements = new Array();
sourceElements = document.getElementsByTagName(tagName);
for (var i = 0; i < sourceElements.length; i++) {
if (sourceElements[i].getAttribute(attrName)) {
if (sourceElements[i].getAttribute(attrName) == attrValue) {
targetElements[targetElements.length] = sourceElements[i];
}
}
}
return targetElements;
}

// Initiated from column header links.
function sortTable(column) {
switch (column) {
case "Title" :
contents.sort(sortByTitle);
break;
case "Author" :
contents.sort(sortByAuthor);
break;
}
// Build the output from the sorted contents array.
var newTable = "";
for (i=0; i<contents.length; i++){
newTable = newTable + contents[i].details;
}
// Write the new table out to the span block.
document.getElementById( "contents" ).innerHTML = '<table width="100%">
' + newTable + "</table>"
}

// JavaScript array sorting. No need to write your own algorithm!!
function sortByTitle(a,b) {
if (a.booktitle<b.booktitle) return -1;
if (a.booktitle>b.booktitle) return 1;
return 0;
}

function sortByAuthor(a,b) {
if (a.author<b.author) return -1;
if (a.author>b.author) return 1;
return 0;
}

With the routines added, I then saved the form and viewed the database through a browser. Figure B shows the browser view with the two column header links that allow us to sort by book title and author.

FIGURE B


This is a Web view of documents in the browser. Roll over picture for a larger image.

Figure C shows the the same view after clicking on the "Author" column title.

FIGURE C


And, here's a Web view of documents sorted by author. Roll over picture for a larger image.

InnerHTML vs. outerHMTL
I use the innerHTML property through out this article instead of the outerHTML property to ensure cross-browser support. Although using outerHTML would have meant I could have lost the Span block and HTML coded into my JavaScript routines, not all browsers support this property so it makes sense when working with multiple browser types to use the more widely supported innerHTML property.

Summary
The technique explained here can be extended very easily to support any number of columns and with only minor changes can also date and time column sorting as required.

Colin Neale is a Notes Consultant and author of C-Search, C-Search for Domino.Doc and the C-Search Mail Monitor. He can be reached at cneale@c-search-solutions.com or http://www.c-search-solutions.com.


« Previous  ·  1  ·  2  ·  3
Other articles you might like
Home > Internet Technologies > JavaScript (13 articles)
   Give your Domino views life with DHTML
   Using dynamically generated HTML to thwart spam email address harvesting
   Implementing dynamic drop-down menus using Domino and Internet Explorer
Home > Lotus Technologies > Domino (77 articles)
   More about Domino log files
   Why your log.nsf might not be purging properly
   Sloppy analysis at the core of another Domino vs. SharePoint report
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
Learn Domino Designer 8.5 for free
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Latest Lotus Headlines
Xpages not loading? JVM errors? - Solution
How to implement an iCalendar feed into your Notes calendar with XPages
DWA Hotfixes for Domino 8.5.1FP1 - A Gotcha
IBM Adds DB2 to Lotus Foundations SMB Package
SNTT : XPages onclick Ghosts in the machine
Ports used by Lotus Sametime 8.5 servers
Exploring a Domino Date Bug
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad defenders have spoken
David Gewirtz Online: CNN commentary and analysis
OutlookPower: More about disappearing text
-- Advertisement --

Find unused Lotus Notes groups and clean up your address book
Have you ever wanted to get rid of old Lotus Notes groups that were cluttering up your address book, but you weren't sure if they were used? Find Unused Groups can help.

Find Unused Groups will check your ACL, mail, multi purpose and server groups to help you determine if they are used, and who uses them.

Learn how to easily clean up your address book.

-- Advertisement --

Integrate your Notes Applications with Microsoft Office and Symphony
Integra for Notes Integrates Microsoft Office and/or IBM Lotus Symphony
Requires NO change to the design of the appliation or Installations of DLL's and EXE's
  • Integra is a ready to use solution, enhance static reports with Excel data analysis, pivot tables, macros
  • User friendly aproach, using a point and click access to features
  • Reports from any Lotus Notes databases
  • Runs reports through a Notes client, web browser and scheduled basis
  • Allows use of LotusScript for advanced data manipulation
  • Enables self service reporting capabilities to end-users


Learn more at www.integra4notes.com.
ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login