Jump to content

How do I add a fixed height setting to the rows/cells of this Table Style code?


Cat

Recommended Posts

I'm trying to create a table for a sheet of labels. I can set a width for the cells and margins, but I cannot set a fixed height for the cells, so the content will not position correctly. The labels are 2.625x1 inches.

Here is the converted rule:

// Rule converted from XML Template "copy_Table Style":
// Begin XML Template selections //
var HasGrid = true; // "Grid": CheckGroup
var GridStyle = "All"; // "Style:" (Required): PickList ["Inside" (Inside), "Outside" (Outside), "All" (All)]
var Color = "Black"; // "Color:" (Required): ColorList
var Thickness = "Thin"; // "Thickness:" (Required): PickList ["Thin" (Thin), "Medium" (Medium), "Thick" (Thick)]
var HasHeaderShading = false; // "Header Shading": CheckGroup
var HeaderColor = "Black"; // "Color:" (Required): ColorList
var HeaderTint = Int("30"); // "Tint (%):" (Required): SingleLine (Integer)
var HasRowShading = false; // "Row Shading": CheckGroup
var RowColor1 = "Black"; // "First Color:" (Required): ColorList
var RowTint1 = Int("30"); // "Tint (%):" (Required): SingleLine (Integer)
var RowColor2 = "White"; // "Second Color:": ColorList
var RowTint2 = Int("30"); // "Tint (%):" (Required): SingleLine (Integer)
// Section "Margins":
var MarginLeft = HundredthsOfPointsFromText("65 pt"); // "Left:": Space (SmallUnits)
var MarginRight = HundredthsOfPointsFromText("10 pt"); // "Right:": Space (SmallUnits)
var MarginTop = HundredthsOfPointsFromText("9 pt"); // "Top:": Space (SmallUnits)
var MarginBottom = HundredthsOfPointsFromText("9 pt"); // "Bottom:": Space (SmallUnits)
// Section "Fonts":
var HeaderStyle = ""; // "Header Font:": CharStyle
var BodyStyle = { "bold": "1", "color": "Black", "family": "Rack Sans", "italic": "0", "pointsize": "24 pt", }; // "Body Font:": CharStyle
// End XML Template selections //

var table = new FPTable;
table.style = { each_cell: {}, headerStyle: HeaderStyle, bodyStyle: BodyStyle };

// Convert 0/1 strings to Boolean.
table.style.headerStyle.bold = HeaderStyle.bold == "1";
table.style.headerStyle.italic = HeaderStyle.italic == "1";
table.style.bodyStyle.bold = BodyStyle.bold == "1";
table.style.bodyStyle.italic = BodyStyle.italic == "1";

if (HasGrid)
{
    if (GridStyle != "Inside")
        table.SetBorders(Thickness, Color, "Top", "Bottom", "Left", "Right");
    
    if (GridStyle != "Outside")
    {
        var eachCellRuling = { Color: Color, Thickness: Thickness };
        // These need to be copied to each cell after the table is populated with data:
        table.style.each_cell.Rulings = { Left: eachCellRuling, Right: eachCellRuling, Top: eachCellRuling, Bottom: eachCellRuling };
    }
}

if (HasHeaderShading)
{
    table.HeaderShadingColor = HeaderColor;
    table.HeaderShadingPct = HeaderTint;    
}

if (HasRowShading)
{
    table.ShadingColor1 = RowColor1;
    table.ShadingPct1 = RowTint1;
    table.ShadingColor2 = RowColor2;
    table.ShadingPct2 = RowTint2;
}

// These need to be copied to each cell after the table is populated with data:
table.style.each_cell.Margins = { Left: MarginLeft, Right: MarginRight, Top: MarginTop / 10, Bottom: MarginBottom / 10 };

return table;

 

Link to comment
Share on other sites

You can't have a set height for table rows.  The whole idea is that cells will expand as necessary to accommodate their contents, and that each row will expand to accommodate the largest cell in the row.

But you can specify a minimum row height, with the minHeight property, and, as long as none of the cells have so much data that they need a larger height, every row will be that minimum size.

You would do this not in the Table Style rule that you show converted to JavaScript, but in the Table rule itself.  Better yet, don't convert either of those rules to JavaScript.  Instead, create a new JavaScript rule to post-process the table, like so:

var table = Rule("Table - from data rule: Your Data"); // <- your table rule name here

for (var r in table.Rows)
    table.Rows[r].minHeight = HundredthsOfPointsFromText("1 in");

return table;

Make sure this rule has the "Re-evaluate this rule for every text flow" and "Treat returned values as tagged text" boxes checked.  Then use this new rule in the output.

Also, note that a whole new table UI, with support for minimum height, without having to write any code at all, is in the works for a future version of FusionPro.

All that said, I do wonder if a table is the best approach to the job as described, "for a sheet of labels."  To me, that description suggests you want to create an imposition job, where the page in your FusionPro template is simply the 2.625x1 inch size, and you create an imposition template (an FPI file) with the FP Imposer tool to output these pages of labels onto imposed sheets.  Then you don't need a table or any code or rule to lay them out; the imposition system does it all for you, based on the settings in the FPI file.

  • Like 1
Link to comment
Share on other sites

Dan,

Now that you mention it, it would make sense to have variable item and allow a spreadsheet upload for the information, and then do the imposition thing.

Sometimes it takes and outside view to state the obvious.

Blarg... and thank you!

Edited by Cat
Link to comment
Share on other sites

  • 5 months later...
On 12/29/2023 at 3:18 AM, Dan Korn said:

You can't have a set height for table rows.  The whole idea is that cells will expand as necessary to accommodate their contents, and that each row will expand to accommodate the largest cell in the row.

But you can specify a minimum row height, with the minHeight property, and, as long as none of the cells have so much data that they need a larger height, every row will be that minimum size.

You would do this not in the Table Style rule that you show converted to JavaScript, but in the Table rule itself.  Better yet, don't convert either of those rules to JavaScript.  Instead, create a new JavaScript rule to post-process the table, like so:

var table = Rule("Table - from data rule: Your Data"); // <- your table rule name here

for (var r in table.Rows)
    table.Rows[r].minHeight = HundredthsOfPointsFromText("1 in");

return table;

Make sure this rule has the "Re-evaluate this rule for every text flow" and "Treat returned values as tagged text" boxes checked.  Then use this new rule in the output.

Also, note that a whole new table UI, with support for minimum height, without having to write any code at all, is in the works for a future version of FusionPro.

All that said, I do wonder if a table is the best approach to the job as described, "for a sheet of labels."  To me, that description suggests you want to create an imposition job, where the page in your FusionPro template is simply the 2.625x1 inch size, and you create an imposition template (an FPI file) with the FP Imposer tool to output these pages of labels onto imposed sheets.  Then you don't need a table or any code or rule to lay them out; the imposition system does it all for you, based on the settings in the FPI file.

Thank you so much for this detailed explanation.  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...