Home › Forums › General XMetaL Discussion › CALS Table Manipulation › Reply To: CALS Table Manipulation
Reply to: CALS Table Manipulation
November 29, 2011 at 9:28 pmThere are no specific methods for inserting tgroup, thead, tbody, or tfoot elements after a table has been inserted (thead and tfoot can be inserted when a table is created, as documented for the InsertCALSTable API).
You should be able to create a Range, move it after a tgroup and then insert a new tgroup there. Your new tgroup will need to have at least one row with at least one entry to be visible. Note that your DTD will need to support multiple tgroup elements inside a table (the CALS standard itself allows this, but some schemas might restrict it to just one). Here's an example:
[code]//XMetaL Script Language JScript:
var rng = ActiveDocument.Range;
if (rng.InContextOfType(“tablecell”)) {
if (rng.MoveToElement(“tgroup”,false)) {
rng.SelectAfterNode(rng.ContainerNode);
//build up your tgroup as a string here, using whatever logic makes the most sense to you (loops, etc)…
var tgroup = '
rng.PasteString(tgroup);
}
}[/code]
Note that in this case your DTD needs to support
insideAnytime you make changes to a table structure in script that are not immediately rendered (this would be the case pretty much anytime you do anything but insert a complete table, or mimic a user action as above) you can call the API formatGraphicTable() to force it to be rendered as a table, or update those bits that are not currently rendered as such. An explanation of why this is the case is included in the docs for this API. If the script above was altered to use DOM or individual InsertElement() calls then that would be necessary.
You may find it easier to enable Plain Text view in XMAX when working with this type of code as it is possible to insert parts of a table that cannot be rendered as a table due to lack of entry elements, etc. Or you might code for XMetaL Author and then once it is working there move it to your XMAX application.