|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROGRAMMING POWER
Sorting your Domino views with JavaScript
By Colin Neale
Have you ever wanted to be able to sort your Domino views in the browser in just the same way that you can from the Notes Client? This article shows one way to achieve column sorting on the Web using some simple JavaScript routines. I use a similar method to allow the sorting of search results in my C-Search products.
Create a simple database I started by creating a database. I added a form and two fields: "Title" and "Author". Next I added some sample documents. Figure A shows these documents when viewed from the Notes Client.
FIGURE A
 
Here's a simple database contents viewed in Notes. Roll over picture for a larger image.
Here sorting is achieved by clicking on each column header. I will now show you how to reproduce this same functionality in the browser.
Create a Web view I proceeded to create a view for the browser. I used multiple columns to make the code easier to follow but you could group all of the HTML into a single column if you prefer. Each column in my Web view is detailed below. The Column-1 formula is simple:
Set to sorted ascending and hidden because we don't want the browser to see it. The Column-2 formula has some table tags:
This defines the start of each table row. Note that I have given the row a "title" attribute. I use title attributes of the "tr" and "td" tags to give me access to the data that I want to sort on.
The Column-3 formula is where some of the hard work begins:
_db := "/" + @ReplaceSubstring(@Subset(@DbName;-1);"\\";"/");
_url := _db + "/0/" + @Text(@DocumentUniqueID) + "?OpenDocument";
"<td width=\"50%\" title=\"booktitle\" abbr=\"" + @UpperCase(Title) + "\"><a href =\"" + _url + "\">" + Title + "</a></td>"
|
This is the first column of the HTML table. It displays the book titles as links. Note, that I use the "title" attribute of the "td" tag here just as I did for the "tr" tag above. For the table columns however I also use the "abbr" attribute to hold the value that I wish to sort by.
Column-4 formula adds a bit more:
"<td width=\"20%\" title=\"author\" abbr=\"" + @UpperCase(Author) + "\">" + Author + "</td>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.
The many included activities and demos will make you a pro! Expert instructor help is a click away.
Click here to try a FREE demo course!! |
-- Advertisement --
Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.
Register by April 10 to save $200. |
|
|
|
|
|
|
|
|
|
|