Ben Langhinrichs

Photograph of Ben Langhinrichs

E-mail address - Ben Langhinrichs

April, 2011
     01 02
03 04 05 06 07 08 09
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Search the weblog

Genii Weblog

Civility in critiquing the ideas of others is no vice. Rudeness in defending your own ideas is no virtue.

Mon 11 Apr 2011, 08:18 PM
Rich Text 2.0 logo

I sometimes feel like the answer to every question I get asked by customer is somewhere buried in this steaming heap of a weblog. In less than a month, this blog will be eight years old, and still requests are made for "new" features that existed in our Midas Rich Text LSX before I started the blog.

Today, I got a question about sorting tables from the web. Of course, there are lots of ways to do that with views or lookups, but this customer has tables which are embedded in rich text fields, and wanted to export them to XHTML or DXL and then use fancy coding techniques to make them into lists, etc. etc. etc.  I did a quick search on the blog, and came up with this handy bit of coding I posted back in 2006.  It does just what the customer asked with a bit of Ajax and a simple agent.

Anyway, here it is, in all its original glory. Of course, Ajax is taken for granted these days, but this was quite the demo in 2006. And, of course, it is still something you can't really do with native Domino (at least not with rich text fields). And, of course, the code is even easier to make work in the Notes client. Incidentally, do you know when I added that SortByRow method to sort a table in a rich text field? Version 1.00 in 1997.

Table to be sorted using Midas and Ajax (for display):

Original sorting...
Que, Suzy 1999150.00-50.00 
Jammer, Jo Jo2001100.00100.00
Jones, Jimmy2002150.00150.00
Lowa, Hona2002156.00120.00
Roxx, Fred2000190.00-10.00
Flintstone, Fred2000200.00100.00
Friend, Dorie2000400.00100.00
Gatwick, George G. 1999600.00150.00
Franklin, James Earl T.1999750.00100.00
Fordick, Mike20031000.001000.00
Hannibal, George20021000.00100.00
Green, Olive20011250.00250.00
Deer, Jane20022003.001000.00
Arnie, Miami20023100.0020.00

Sort by column 1
Sort descending by column 1
Sort numerically by column 2
Sort numerically descending by column 2
Sort numerically by column 3
Sort numerically descending by column 3

So, what is happening in this demo?  The agent code is really, really simple, so I thought I would just put it here in-line for you to look at:

Sub Initialize
   Dim session As New NotesSession
   Dim db As NotesDatabase
   Dim doc As NotesDocument
   Dim rtitem As New GeniiRTItem
   Dim rtchunk As GeniiRTChunk
   Dim unid As String
   Dim pos As Integer
   Dim column As Integer
   Dim reverse As Integer
   Dim numeric As Integer
'   &Sort=unid&Column=1&Numeric=Yes|No&Reverse=Yes|No
   Set db = session.CurrentDatabase
   Set doc = session.DocumentContext
   pos = Instr(doc.Query_String(0), "&Sort=")
   unid=Mid(doc.Query_String(0), pos+6, 32)
   pos = Instr(doc.Query_String(0), "&Column=")
   column = Cint(Mid(doc.Query_String(0), pos+8, 1))
   pos = Instr(doc.Query_String(0), "&Numeric=")
   numeric = Cint(Mid(doc.Query_String(0), pos+9, 1))   
   pos = Instr(doc.Query_String(0), "&Reverse=")
   reverse = Cint(Mid(doc.Query_String(0), pos+9, 1))      
   Set doc = db.GetDocumentByUNID(unid)
   Call rtitem.ConnectBackend(doc.Handle, "BlogBodyRT", True)
   Set rtchunk = rtitem.DefineChunk("Table 1")
   Call rtchunk.SortByRow(column, True, numeric, reverse)
   Print rtchunk.GenerateHTML("Table 1", "HTML", "Generation='Fragment' StandardFontTags='Yes' ")
End Sub

And that is it.  Midas reads the contents of this blog post itself, sorts the table and then spits out the content again into the space occupied before by the table, all using Ajax.  It never saves the changes, so dozens of people can try this at the same time without causing conflicts.  

Of course there are other ways to accomplish this. There are other ways to accomplish anything. But ask anyone who has ever worked with the Midas Rich Text LSX, and they'll tell you, it's just plain easy and intuitive. Did you ever stop to think about using Midas with Ajax and Xpages in a modern website?

Copyright 2011 Genii Software Ltd.