Data Table (HUH) – What is it good for?
With apologies to Edwin Starr*, this is a question that I’m pondering.
I haven’t heard much about the Data Table control (aside from the coverage in the Mastering XPages book), but I’m in the process of working through several display controls in XPages to make sure I know them well enough to make the best decision for each application that I develop. (Foreshadowing alert — look for information on additional controls in the near future.)
Creating a Data Table
If you drag a data table control onto an XPage or custom control, this is what you get by default:
<xp:dataTable id="dataTable1" rows="30"> <xp:column id="column1"></xp:column> <xp:column id="column2"></xp:column> </xp:dataTable>
There are three rows displayed in the XSP editor for the header, body, and footer, respectively.
It’s essentially the shell of a table that you need to manually configure by adding your own controls and binding them. This makes it much more like a repeat control. Compare that to a view panel, where you are prompted for a data source and all of the selected columns are set up and bound automatically.
On the Data Table subtab of the Properties panel, you can select a data source (view, document, or object data source, if you have the extension library or UP1), set the number of rows to display (Repeat limit), set the variable to programmatically access each row (Collection name), and set the variable to access the row number (Index name).
The Collection name is necessary because there would be no other way to access each row to bind data. You can use expression language or SSJS to bind the values to underlying view columns, but, according to the Mastering XPages book, view columns with dollar signs ($) in the name are problematic with EL, so watch out for that. For cases when you can use EL, it’s easy enough to just pick the column name based on the Collection name variable.
On the Display subtab of the Properties panel, you only have two options: Show pager in header and Show pager in footer. Once you select one or both of those options, you will get a pager control for the control, which you can modify.
On the All Properties subtab of the Properties panel, under ‘data’, you can see that there are very few options for working with the data. No way to search or filter or set a start key.
The Default Result
Here’s what it looks like when I add two labels and two controls bound to view columns, along with a pager in the header:
So, it looks to me like this is a lightweight repeat control-ish way to display some view data.
You have more flexibility with the UI because you’re not locked into view columns, but it will be a manual undertaking. Repeat controls also have that flexibility and there’s a lot you can do to customize view panel columns (see this blog post or this episode of NotesIn9 for more information), so I’m not sure where this control would come into play.
The lack of options for working with the data makes it hard for me to see how this could be useful other than with a very small set of information.
If you’ve ever used a data table, let me know. I’m curious to hear the use case.
* (This reference is in no way an endorsement of the song or its message — the hook just popped into my head. If you recognize it, it’s probably stuck in yours now, too!)