Susan Posted July 12, 2017 Share Posted July 12, 2017 I've attached a sample of a table and was wondering if it would be possible to create a table like this where some of the entries would straddle the columns. Here is my usual table rule where the columns don't straddle. if(FusionPro.Composition.isPreview == true || FusionPro.inValidation == true) { Rule("OnJobStart"); } //Get a count of the total number of records in the external data file numRecsExtDF = externalDF.recordCount; /*============================================================================= || Create arrays to hold values that match the CID of the client's record ||=============================================================================*/ var clientMatch = []; var eventMatch = []; var locationMatch = []; var secMatch = []; var rowMatch = []; var seatMatch = []; var qtyMatch = []; var priceMatch = []; var extendedMatch = []; // Step through the external data file and push matches into their respective variables if there is a match for (var i=1; i <= numRecsExtDF; i++) { if (externalDF.GetFieldValue(i, 'USERACCOUNTNUMBER') == Field("USERACCOUNTNUMBER")) { clientMatch.push(externalDF.GetFieldValue(i, 'USERACCOUNTNUMBER')); eventMatch.push(externalDF.GetFieldValue(i, 'cEvent_Package')); locationMatch.push(externalDF.GetFieldValue(i, 'cLocation')); secMatch.push(externalDF.GetFieldValue(i, 'cSec')); rowMatch.push(externalDF.GetFieldValue(i, 'cRow')); seatMatch.push(externalDF.GetFieldValue(i, 'cSeats')); qtyMatch.push(externalDF.GetFieldValue(i, 'TOTAL_COUNT')); priceMatch.push(externalDF.GetFieldValue(i, 'SEAT_PRICE')); extendedMatch.push(externalDF.GetFieldValue (i, 'EXTENDED_AMOUNT')); } } /*============================================================================= || Create the table ||=============================================================================*/ new FPTable; var myTable = new FPTable; myTable.AddColumns(19800, 6200, 5700, 3800,6200,2650,5450,6150) myTable.AddRows(clientMatch.length+2); // add 2 additional rows (Header and summary lines) // HEADER ROW FORMATTING myTable.Rows[0].Type = "Header"; myTable.Rows[0].Cells[0].Font = "Helvetica Neue Bold Condensed"; myTable.Rows[0].Cells[0].PointSize = "10"; myTable.Rows[0].Cells[0].TextColor = "White"; myTable.Rows[0].Cells[0].ShadeColor = "Black"; myTable.Rows[0].Cells[0].ShadePct = 50; myTable.Rows[0].Cells[0].Margins = new FPTableMargins; myTable.Rows[0].Cells[0].Margins.Top = 30; myTable.Rows[0].Cells[0].Margins.Bottom = 45; myTable.Rows[0].Cells[0].Margins.Right = 500; myTable.Rows[0].Cells[0].SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left"); myTable.Rows[0].CopyCells(0, 1, 2, 3,4,5,6,7); // Apply the same formating to each cell in this row // HEADER ROW CONTENT myTable.Rows[0].Type = "Header"; myTable.Rows[0].Cells[0].HAlign = "Left"; myTable.Rows[0].Cells[1].HAlign = "Left"; myTable.Rows[0].Cells[2].HAlign = "Center"; myTable.Rows[0].Cells[3].HAlign = "Center"; myTable.Rows[0].Cells[4].HAlign = "Center"; myTable.Rows[0].Cells[5].HAlign = "Center"; myTable.Rows[0].Cells[6].HAlign = "Center"; myTable.Rows[0].Cells[7].HAlign = "Center"; myTable.Rows[0].SetContents("Event / Package", "Location", "Sec", "Row", "Seat(s)", "Qty", "Price", "Total"); // interate through the length of the arrays (data matches from external data file) and create rows for (var i=1; i<=clientMatch.length; i++) { // TABLE CONTENT FORMATTING myTable.Rows.Cells[0].Font = "HelveticaNeueLT Std Cn"; myTable.Rows.Cells[0].PointSize = "10"; myTable.Rows.Cells[0].Margins = new FPTableMargins; myTable.Rows.Cells[0].Margins.Top = 50; myTable.Rows.Cells[0].Margins.Bottom = 30; myTable.Rows.Cells[0].Margins.Right = 500; myTable.Rows.Cells[0].Margins.Left = 500; myTable.Rows.Cells[0].SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left"); myTable.Rows.CopyCells(0,1,2,3,4,5,6,7); // Apply the same formating to each cell in this row // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS myTable.Rows.Cells[0].VAlign = "Middle"; myTable.Rows.Cells[1].VAlign = "Middle"; myTable.Rows.Cells[2].VAlign = "Middle"; myTable.Rows.Cells[3].VAlign = "Middle"; myTable.Rows.Cells[4].VAlign = "Middle"; myTable.Rows.Cells[5].VAlign = "Middle"; myTable.Rows.Cells[6].VAlign = "Middle"; myTable.Rows.Cells[7].VAlign = "Middle"; myTable.Rows.SetContents(eventMatch[i-1], locationMatch[i-1], secMatch[i-1], rowMatch[i-1], seatMatch[i-1], qtyMatch[i-1], priceMatch[i-1], extendedMatch[i-1]); myTable.Rows.Cells[0].HAlign = "Left"; myTable.Rows.Cells[1].HAlign = "Left"; myTable.Rows.Cells[2].HAlign = "Center"; myTable.Rows.Cells[3].HAlign = "Center"; myTable.Rows.Cells[4].HAlign = "Center"; myTable.Rows.Cells[5].HAlign = "Center"; myTable.Rows.Cells[6].HAlign = "Right"; myTable.Rows.Cells[7].HAlign = "Right"; myTable.Rows.SetContents(eventMatch[i-1], locationMatch[i-1], secMatch[i-1], rowMatch[i-1], seatMatch[i-1], qtyMatch[i-1], "$"+priceMatch[i-1], "$"+extendedMatch[i-1]); } return myTable.MakeTags(); Quote Link to comment Share on other sites More sharing options...
step Posted July 13, 2017 Share Posted July 13, 2017 I'm sure there are many ways to do that. You could add something like this after you set the contents of the row that will set the horizontal straddle property of those specific cells based on whether or not a given field has a value: var eventCell = myTable.Rows[i].Cells[0]; eventCell.HStraddle = 1 + !locationMatch[i-1]; var secCell = myTable.Rows[i].Cells[2]; secCell.HStraddle = 1 + !rowMatch[i-1] + !seatMatch[i-1]; Another (possibly more versatile) option is to use a for loop that sets the horizontal straddle value based on the content of the adjacent cell: // For each cell position (c), set the horizontal straddle value. for (var c = 0; c < myTable.Rows[i].Cells.length - 1; c++) { var straddle = 1; // Increment the straddle value of a given cell for every // adjacent cell that does not contain a value. while (!myTable.Rows[i].Cells[c + straddle].Content) straddle++; // Assign the straddle value for this cell. myTable.Rows[i].Cells[c].HStraddle = straddle; } As a side note, there are a few things you could do to clean your code up a little bit. First of all you're setting the content of the row twice – which isn't necessary: myTable.Rows[i].Cells[0].VAlign = "Middle"; myTable.Rows[i].Cells[1].VAlign = "Middle"; myTable.Rows[i].Cells[2].VAlign = "Middle"; myTable.Rows[i].Cells[3].VAlign = "Middle"; myTable.Rows[i].Cells[4].VAlign = "Middle"; myTable.Rows[i].Cells[5].VAlign = "Middle"; myTable.Rows[i].Cells[6].VAlign = "Middle"; myTable.Rows[i].Cells[7].VAlign = "Middle"; [color="red"]myTable.Rows[i].SetContents(eventMatch[i-1], locationMatch[i-1], secMatch[i-1], rowMatch[i-1], seatMatch[i-1], qtyMatch[i-1], priceMatch[i-1], extendedMatch[i-1]);[/color] myTable.Rows[i].Cells[0].HAlign = "Left"; myTable.Rows[i].Cells[1].HAlign = "Left"; myTable.Rows[i].Cells[2].HAlign = "Center"; myTable.Rows[i].Cells[3].HAlign = "Center"; myTable.Rows[i].Cells[4].HAlign = "Center"; myTable.Rows[i].Cells[5].HAlign = "Center"; myTable.Rows[i].Cells[6].HAlign = "Right"; myTable.Rows[i].Cells[7].HAlign = "Right"; [color="Red"]myTable.Rows[i].SetContents(eventMatch[i-1], locationMatch[i-1], secMatch[i-1], rowMatch[i-1], seatMatch[i-1], qtyMatch[i-1], "$"+priceMatch[i-1], "$"+extendedMatch[i-1]);[/color] Secondly, since you're setting the VAlign property of each cell to "Middle," why not move it up a few lines, apply it to the first cell and let the "CopyCells" method apply it to the rest of them: myTable.Rows[i].Cells[0].Margins = new FPTableMargins; myTable.Rows[i].Cells[0].Margins.Top = 50; myTable.Rows[i].Cells[0].Margins.Bottom = 30; myTable.Rows[i].Cells[0].Margins.Right = 500; myTable.Rows[i].Cells[0].Margins.Left = 500; myTable.Rows[i].Cells[0].SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left"); myTable.Rows[i].CopyCells(0,1,2,3,4,5,6,7); // Apply the same formating to each cell in this row // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS [color="red"]myTable.Rows[i].Cells[0].VAlign = "Middle"; myTable.Rows[i].Cells[1].VAlign = "Middle"; myTable.Rows[i].Cells[2].VAlign = "Middle"; myTable.Rows[i].Cells[3].VAlign = "Middle"; myTable.Rows[i].Cells[4].VAlign = "Middle"; myTable.Rows[i].Cells[5].VAlign = "Middle"; myTable.Rows[i].Cells[6].VAlign = "Middle"; myTable.Rows[i].Cells[7].VAlign = "Middle";[/color] myTable.Rows[i].Cells[0].Margins = new FPTableMargins; myTable.Rows[i].Cells[0].Margins.Top = 50; myTable.Rows[i].Cells[0].Margins.Bottom = 30; myTable.Rows[i].Cells[0].Margins.Right = 500; myTable.Rows[i].Cells[0].Margins.Left = 500; myTable.Rows[i].Cells[0].SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left"); [color="red"]myTable.Rows[i].Cells[0].VAlign = "Middle";[/color] myTable.Rows[i].CopyCells(0,1,2,3,4,5,6,7); // Apply the same formating to each cell in this row Quote Link to comment Share on other sites More sharing options...
Susan Posted July 13, 2017 Author Share Posted July 13, 2017 Thanks for cleaning up my table rule. I am having trouble getting the first Code to work. The "Event/Package" straddles correctly, but the "Sec" is only straddling into "Row" and not "Row" and "Seat(s)" and "Seat(s) and "Qty" straddle. On the more versatile code I get an error on this line while (!myTable.Rows.Cells[c + straddle].Content) straddle++; Finally, if I can get any of these to work, is it possible to have "Sec" flush left only when it straddles as opposed to centering. I've attached a sample FP file if you have a chance to look at it. Thanks Ste. Quote Link to comment Share on other sites More sharing options...
Susan Posted July 13, 2017 Author Share Posted July 13, 2017 It looks like my file didn't attach. I'll try again. Quote Link to comment Share on other sites More sharing options...
Susan Posted July 13, 2017 Author Share Posted July 13, 2017 Can't seem to get my file to attach. I'll try once more. Got it!Sample.zip Quote Link to comment Share on other sites More sharing options...
step Posted July 13, 2017 Share Posted July 13, 2017 Thanks for cleaning up my table rule. I am having trouble getting the first Code to work. The "Event/Package" straddles correctly, but the "Sec" is only straddling into "Row" and not "Row" and "Seat(s)" and "Seat(s) and "Qty" straddle. Looks like you put it in the wrong place. Should be: // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS myTable.Rows[i].Cells[0].HAlign = "Left"; myTable.Rows[i].Cells[1].HAlign = "Left"; myTable.Rows[i].Cells[2].HAlign = "Center"; myTable.Rows[i].Cells[3].HAlign = "Center"; myTable.Rows[i].Cells[4].HAlign = "Center"; myTable.Rows[i].Cells[5].HAlign = "Center"; myTable.Rows[i].Cells[6].HAlign = "Right"; myTable.Rows[i].Cells[7].HAlign = "Right"; myTable.Rows[i].SetContents(eventMatch[i-1], locationMatch[i-1], secMatch[i-1], rowMatch[i-1], seatMatch[i-1], qtyMatch[i-1], "$"+priceMatch[i-1], "$"+extendedMatch[i-1]); [color="Red"]var eventCell = myTable.Rows[i].Cells[0]; eventCell.HStraddle = 1 + !locationMatch[i-1]; var secCell = myTable.Rows[i].Cells[2]; secCell.HStraddle = 1 + !rowMatch[i-1] + !seatMatch[i-1];[/color] On the more versatile code I get an error on this line while (!myTable.Rows[i].Cells[c + straddle].Content) straddle++; While it would have been helpful if you had actually included the error you're referencing, I'm just going to assuming you put that code in the wrong place as well. It should be: // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS myTable.Rows[i].Cells[0].HAlign = "Left"; myTable.Rows[i].Cells[1].HAlign = "Left"; myTable.Rows[i].Cells[2].HAlign = "Center"; myTable.Rows[i].Cells[3].HAlign = "Center"; myTable.Rows[i].Cells[4].HAlign = "Center"; myTable.Rows[i].Cells[5].HAlign = "Center"; myTable.Rows[i].Cells[6].HAlign = "Right"; myTable.Rows[i].Cells[7].HAlign = "Right"; myTable.Rows[i].SetContents(eventMatch[i-1], locationMatch[i-1], secMatch[i-1], rowMatch[i-1], seatMatch[i-1], qtyMatch[i-1], "$"+priceMatch[i-1], "$"+extendedMatch[i-1]); [color="red"]// For each cell position (c), set the horizontal straddle value. for (var c = 0; c < myTable.Rows[i].Cells.length - 1; c++) { var straddle = 1; // Increment the straddle value of a given cell for every // adjacent cell that does not contain a value. while (!myTable.Rows[i].Cells[c + straddle].Content) straddle++; // Assign the straddle value for this cell. myTable.Rows[i].Cells[c].HStraddle = straddle; }[/color] Finally, if I can get any of these to work, is it possible to have "Sec" flush left only when it straddles as opposed to centering. Sure: // For each cell position (c), set the horizontal straddle value. for (var c = 0; c < myTable.Rows[i].Cells.length - 1; c++) { var straddle = 1; // Increment the straddle value of a given cell for every // adjacent cell that does not contain a value. while (!myTable.Rows[i].Cells[c + straddle].Content) straddle++; // Assign the straddle value for this cell. myTable.Rows[i].Cells[c].HStraddle = straddle; [color="Red"] // Align text to the left if straddling multiple cells. if (straddle > 1) myTable.Rows[i].Cells[c].HAlign = "Left";[/color] } Or: var secCell = myTable.Rows[i].Cells[2]; secCell.HStraddle = 1 + !rowMatch[i-1] + !seatMatch[i-1]; [color="red"]if (secCell.HStraddle > 1) secCell.HAlign = "Left";[/color] Quote Link to comment Share on other sites More sharing options...
Susan Posted July 14, 2017 Author Share Posted July 14, 2017 Both versions of code are working great. Thanks for all your help and for sharing your knowledge. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.