|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- 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. |
|
|
|
|
|
|
|
|
|
|