Skip to main content
Inspiring
August 29, 2024
Answered

How to use "keep with next" feature for a table row when using Structured documents (i.e. DITA)

  • August 29, 2024
  • 2 replies
  • 1562 views

I have a table in which I want to use the "keep with next row" feature. However, I am using DITA, and so the "keep with row" property that is nominally available with FM is not saved with the .DITA file. How do I do this?

 

My attempt:

I know how to modify my EDD files to define choices for outputclass attribute of a table row (i.e. create a new choice "keep with next row" so that the author can select this option when editing). I also know how to add context rules to the EDD to be able to change the style/formatting based on a particular choice of outputclass (i.e. so that the PDF rendering uses a different format/style). What I am not sure how to do is define a style/format for a table row that would "keep with next", because the "keep with next" property is not part of the Table designer. 

 

Q1: Is my approach possible, and if so how would I do it?

 

Q2: Is there another approach that would work and allow an author to "simply" select/indicate that a particular row should be kept with next?

 

Note: I am aware of the solution proposed by @frameexpert  in https://community.adobe.com/t5/framemaker-discussions/is-it-possible-to-group-rows-of-a-table-and-then-apply-the-orphan-rows-to-them/m-p/11943045. I was able to get that solution to "work", but it is not a super-user-friendly solution for the authors I work with because I could only make the column "invisible" by manually opening the .DITA file in Notepad++ and manually editing the colspec attribute: colwidth="0.1". I would prefer that the authors can do everything they need in FM.

This topic has been closed for replies.
Correct answer frameexpert

Thanks. I was starting to look up how to do that, but then realized I should confirm a couple of things:

  • Will this work with DITA files? If so, how does one apply a condition to a column in a table?
  • Does this require a script?

This 5-minute video will answer your questions.

https://youtu.be/uAdTXp5eY2o

2 replies

frameexpert
Community Expert
August 30, 2024

Here is a teaser script that will allow you to use DITA markup to control Keep With Next Row setting. Follow these steps to set it up:

  1. Open a DITA topic that has tables in it.
  2. Go to your row or rows that you want to set to keep with next row.
  3. Change the outputclass attribute on the row element(s) to "keep-next".
  4. Run the script below.

 

#target framemaker

main ();

function main () {

    var doc, element;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        // Make sure the document is structured.
        element = doc.MainFlowInDoc.HighestLevelElement;
        if (element.ObjectValid () === 1) {
            processDoc (doc, element);
        }
    }
}

function processDoc (doc, element) {
    
    var tbls, count, i;
    
    if (app.Displaying === 1) {
        app.Displaying = 0;
    }

    // Get all of the tables in the document's main flow.
    tbls = getMainFlowTables (doc);
    // Process each table.
    count = tbls.length;
    for (i = 0; i < count; i += 1) {
        processTbl (tbls[i], doc);
    }
    
    if (app.Displaying === 0) {
        app.Displaying = 1;
        doc.Rehyphenate ();
        doc.Redisplay ();
    }
}

function processTbl (tbl, doc) {
    
    var row, element, value;
    
    // Loop through the rows in the table.
    row = tbl.FirstRowInTbl;
    while (row.ObjectValid () === 1) {
        // Get the row element of the row object.
        element = row.Element;
        value = getAttributeValue (element, "outputclass");
        if ((value) && (value === "keep-next")) {
            row.RowKeepWithNext = 1;
        }
        else {
            row.RowKeepWithNext = 0;
        }
        row = row.NextRowInTbl;
    }
}

function getMainFlowTables (doc) {
    
    var tbls, textList, count, i;
    
    // Make an array for the table objects.
    tbls = [];
    
    // Get all the table text items from the main flow of the document.
    textList = doc.MainFlowInDoc.GetText (Constants.FTI_TblAnchor);
    count = textList.length;
    // Add each Tbl object to the array.
    for (i = 0; i < count; i += 1) {
        tbls.push (textList[i].obj);
    }
    
    // Return the array.
    return tbls;    
}

function getAttributeValue (element, name) {
    
	var attrList, count, i;
	
    attrList = element.Attributes;
    count = attrList.length;
    for (i = 0; i < count; i += 1) {
        if (attrList[i].name === name) {
            if (attrList[i].values[0] !== undefined) {
                return (attrList[i].values[0]);
            }
        }
    }
}

Why do I call it a teaser script?

  1. Because you have to run it manually every time you open a topic in FrameMaker. A production version would be run automatically whenever you open a topic.
  2. I have only added the option for Keep With Next Row ("keep-next"). A production script could add other options such as "keep-previous", "next-page", "next-column", etc. In other words, you would have options to match what is in the Row Format dialog box.
  3. Any other things that amazing users like you come up with.

 

frameexpert
Community Expert
September 12, 2024

This was the answer I was hoping that was marked correct. Here is a video about a free script that you try:

https://youtu.be/tU8vshrS2sA?si=A3jxcxqLgstl-tv0

Ian16B7Author
Inspiring
September 13, 2024

@frameexpertsorry! I think these are both good answers. I selected the other answer for two reason:

- I have not used any scripts with FM before

- the other solution can solve other, related problems as well

So for anyone else reading his - please look at both answers!

frameexpert
Community Expert
August 29, 2024

You could have the DITA authors set an outputclass attribute value of, say for instance, "keep-with-next" on those rows. However, you can't use the EDD to automatically set the row format to Keep With Next Row, based on the attribute value. You would need a script that would look for this outputclass value and programmatically set the property on the table row. The script would be relatively straightforward.

Ian16B7Author
Inspiring
August 29, 2024

Thanks. I will have to ponder the script approach.

 

Having started to play with the invisible column approach, it does have some advantages (i.e. explicitly organizing a group of rows). However, I also discovered that I did not fully/properly test this approach. It turns out that when a .DITA file is opened and saved, it will auto-magically change colwidth="0.1" to colwidth="0*", which creates a rather wide/visible column. So as long as I do not save the .DITA file, the colwidth="0.1" will be kept (and used), which is a bit awkward. colwidth="1*" is kept, but that is still visible.

 

Any other suggestions on how to make a column in a table invisible? Or does that also require a script?

Ian16B7Author
Inspiring
August 29, 2024

You can apply a Condition Format to a table column, then hide the Condition.


Thanks. I was starting to look up how to do that, but then realized I should confirm a couple of things:

  • Will this work with DITA files? If so, how does one apply a condition to a column in a table?
  • Does this require a script?