It's been asked many times how this can be accomplished. And there have been a number of clever methods attempted but I thought there *must* be a simpler way.
Well I think I have it - Infopath stores the display formatting information for each of its views in XSL files, which are packaged up in the XSN template file.
XSL files are XML transforms - they are used by Infopath in this case to generate HTML style formatting out of the raw XML data saved in a form and display it.
Looking at the XSL files in notepad I see that CSS styles appear quite prominently. So I Googles a bit and found that TABLES in HTML can be made up of <THEAD> and <TBODY> tags.
Inside of Infopath XSL files there are lots of <TBODY> entries for repeating tables, but instead of <THEAD> for table headers, it uses <TBODY class="xdTableHeader"> tags.
The 'class' attribute here tells Infopath what CSS style to use from those defined at the top of the XSL.
Well, <THEAD> tag (according to CSS documentation) has a style attribute: style="DISPLAY: table-header-group", which tells a web browser to repeat the header every printed page.
So after a bit of experimenting I managed to get a template which behaves as we want and I've attached it.
PROBLEM: As soon as you make any change to the template/table in the design view Infopath turns all the THEADs back into TBODYs!
So it means that this 'solution' has to be the last thing you do, every time you make a form change - which is to say the least, irritating.
Here is the process I used to make the modification:
- Extract form source files using File > Extract Files or File > Save As Source Files (IP2007)
- Go to the extracted files folder
- Open up the XSL file corresponding to the View you want to alter the repeating table on in a text editor (Windows Notepad does fine)
- Do a Search for <tbody class="xdTableHeader"> - and keep searching until you find the one which is followed by <tr> and <td> tags which match your repeating table headers.
- Replace <tbody class="xdTableHeader"> with <thead class="xdTableHeader" style="DISPLAY: table-header-group"
- Find the </tbody> closing tag which used to mark the end of the table header <tr> and <td> tags (it's usually right before another <tbody> tag)
- Replace that </tbody> tag with </thead>
- Save the xsl file
Now find the xsf file in the extracted files, right-click and design. Go to Preview and insert a ton of rows into your repeating table. Select File > Print Preview and you should see that your table header is repeated on each page that the repeating tabled travels over!
DON'T make ANY changes to the view layout - as soon as you do Infopath will get rid of all your THEAD work.
File > Publish your form again to a new location to 'recompile' all the extracted form files back into a single xsn file, this xsn will maintain the THEAD behaviour.
So what's the next step?
Well - taking inspiration from Microsofts own DownLevel tools - I think I will build a small script which does all the above for us automatically, eliminating the irritating rework every publish.
Should I make the script/tool to automate this?
Yes please! (0%)
Don't bother. (100%)