Monday, March 5, 2007

Tip about tables

Today, I was rewriting a search-agent at work.

The agent is used to search for unbooked cabins. First it searches for the cabins matching some criteria. Using the collection that is returned, It then looks for bookings (which are made from another form than the cabin-documents) on the cabins that are found. When a cabin is found, the HTML for that cabin is printed.

The counter of found cabins, which I had to print, is not available until all the HTML for the cabins is printed.

I considered adding line-breaks at the top of the table containing the result, and absolutely positioning the count at the top. I then remembered reading something about thead, tfoot and tbody being "non-chronological". The solution was putting all the cabins from the result in a tbody tag. Then printing the thead-tag with the number of results at the bottom.

<tr><td>Cabin at the mountains.</td></tr>
<tr><td>Cabin at the tundra.</td></tr>
<td colspan="2">Found 2 cabins matching the search criteria:</td>

Result (faked with div, because of blogspot escaping code):

Found 2 cabins matching the search criteria:

Cabin at the mountains.

Cabin at the tundra.