Susan Posted September 18, 2014 Share Posted September 18, 2014 I've created tables before using the table rule but am having trouble with creating a table with 2 rows per entry. I've attached a screen shot of a sample. Can this be done? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 18, 2014 Share Posted September 18, 2014 Yes, that can be done. Presumably you're iterating something like data from an external data file. Just call FPTable.AddRow twice for each record of data, and populate each row appropriately. You can use the FPTableCell.HStraddle property to "merge" cells in the same row. Quote Link to comment Share on other sites More sharing options...
Susan Posted September 18, 2014 Author Share Posted September 18, 2014 Here is the table rule I am using for a similar table. Could you let me know where I would put "FPTable.AddRow". I already have "myTable.AddRows(clientMatch.length+2);" in the rule. Thanks. 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(15000, 10500, 5650, 3700,7200,2450,4950,5400) 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 = 40; myTable.Rows[0].Cells[0].Margins.Right = 500; myTable.Rows[0].Cells[0].Margins.Left = 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 = 55; myTable.Rows.Cells[0].Margins.Bottom = 55; 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...
Dan Korn Posted September 18, 2014 Share Posted September 18, 2014 Well, it's hard to know exactly what to do just from looking at the rule, without the rest of the job and the data to test against, but I would rework the rule a bit, like so (starting after the "Create the table" comment): var myTable = new FPTable; myTable.AddColumns(15000, 10500, 5650, 3700,7200,2450,4950,5400); // HEADER ROW FORMATTING var row = myTable.AddRow(); row.Type = "Header"; for (var c = 0; c < myTable.Columns.length; c++) { var cell = row.Cells[c]; cell.Font = "Helvetica Neue Bold Condensed"; cell.PointSize = "10"; cell.TextColor = "White"; cell.ShadeColor = "Black"; cell.ShadePct = 50; cell.Margins = { Top:30, Bottom:40, Right:500, Left:500 }; cell.SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left"); cell.HAlign = c < 2 ? "Left" : "Center"; } // HEADER ROW CONTENT row.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 = 0; i < clientMatch.length; i++) { // TABLE CONTENT FORMATTING var row = myTable.AddRow(); for (var c = 0; c < myTable.Columns.length; c++) { var cell = row.Cells[c]; cell.Font = "HelveticaNeueLT Std Cn"; cell.PointSize = "10"; cell.Margins = { Top:55, Bottom:55, Right:500, Left:500 }; cell.SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left"); cell.VAlign = "Middle"; cell.HAlign = c < 2 ? "Left" : (c < 6 ? "Center" : "Right"); } // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS row.SetContents(eventMatch[i], locationMatch[i], secMatch[i], rowMatch[i], seatMatch[i], qtyMatch[i], priceMatch[i], extendedMatch[i]); var row = myTable.AddRow(); for (var c = 0; c < myTable.Columns.length; c++) { var cell = row.Cells[c]; cell.Font = "HelveticaNeueLT Std Cn"; cell.PointSize = "10"; cell.Margins = { Top:55, Bottom:55, Right:500, Left:500 }; cell.SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left"); cell.VAlign = "Middle"; cell.HAlign = c < 2 ? "Left" : (c < 6 ? "Center" : "Right"); } row.Cells[0].HStraddle = myTable.Columns.length; row.Cells[0].Content = "This is another table row for each record found in the XDF!"; } return myTable.MakeTags(); Here, you can see that, instead of a single call to AddRows at the start, we simply call AddRow as needed. You can also see that there's a second call to AddRow in each iteration of the loop, which adds a second table row for each record matched in the external data file. There's also an example of using the HStraddle property. Quote Link to comment Share on other sites More sharing options...
Susan Posted September 18, 2014 Author Share Posted September 18, 2014 Thanks Dan, was able to build my table using your code. Quote Link to comment Share on other sites More sharing options...
Susan Posted September 19, 2014 Author Share Posted September 19, 2014 I have one more issue with this table. There are some fields in my External Data that have ampersands that are giving me an error - Incomplete entity definition Q. I'm having trouble figuring out where to insert a "TaggedTextFromRaw" in my code. 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 dateMatch = []; var zoneMatch = []; var neighborhoodMatch = []; var pricecodeMatch = []; 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')); dateMatch.push(externalDF.GetFieldValue(i, 'EVENT_START_DATE_cal')); zoneMatch.push(externalDF.GetFieldValue(i, 'ZONE_DESC')); neighborhoodMatch.push(externalDF.GetFieldValue(i, 'NBRHOOD_DESC')); pricecodeMatch.push(externalDF.GetFieldValue(i, 'PRICE_CODE_DESC')); 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(2700, 13500, 6300, 10800,6300,2700,6300,6300); // HEADER ROW FORMATTING var row = myTable.AddRow(); row.Type = "Header"; for (var c = 0; c < myTable.Columns.length; c++) { var cell = row.Cells[c]; cell.Font = "GothamHTF-BoldCondensed"; cell.PointSize = "10"; cell.TextColor = "White"; cell.ShadeColor = "Black"; cell.ShadePct = 100; cell.Margins = { Top:40, Bottom:40, Right:500, Left:500 }; row.Cells[0].HStraddle = "2" row.Cells[5].HStraddle = "3" cell.SetBorders("Very Thin", "White","Right", "Left"); cell.HAlign = "Left"; } // HEADER ROW CONTENT row.SetContents("Event / Package", "","Date", "Zone", "Neighborhood", "Price Code", "", "", ""); var row = myTable.AddRow(); row.Type = "Header"; for (var c = 0; c < myTable.Columns.length; c++) { var cell = row.Cells[c]; cell.Font = "GothamHTF-BoldCondensed"; cell.PointSize = "10"; cell.TextColor = "White"; cell.ShadeColor = "Black"; cell.ShadePct = 50; row.Cells[0].ShadeColor = "white"; row.Cells[3].HStraddle = "2" cell.Margins = { Top:40, Bottom:40, Right:500, Left:500 }; cell.SetBorders("Very Thin", "White","Right", "Left"); cell.HAlign = "Center"; } // HEADER ROW CONTENT row.SetContents("","Section","Row", "Seat", "","Qty", "Price Each", "Ticket Total"); // interate through the length of the arrays (data matches from external data file) and create rows for (var i = 0; i < clientMatch.length; i++) { // TABLE CONTENT FORMATTING var row = myTable.AddRow(); for (var c = 0; c < myTable.Columns.length; c++) { var cell = row.Cells[c]; row.Cells[0].ShadeColor = "white"; cell.ShadeColor = "white"; cell.ShadePct = 100; cell.Margins = { Top:1, Bottom:1}; cell.VAlign = "Middle"; cell.HAlign = "Center"; // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS row.SetContents("", "", "", "", "", "", "", ""); } var row = myTable.AddRow(); for (var c = 0; c < myTable.Columns.length; c++) { row.SetContents(eventMatch, dateMatch, zoneMatch, neighborhoodMatch, pricecodeMatch); var cell = row.Cells[c]; cell.Font = "GothamHTF-LightCondensed"; cell.PointSize = "10"; cell.TextColor = "Black"; cell.ShadeColor = "Black"; cell.ShadePct = 25; row.Cells[0].HStraddle = "2" row.Cells[5].HStraddle = "3" cell.Margins = { Top:40, Bottom:40, Right:500, Left:500 }; cell.SetBorders("Very Thin", "White", "Right", "Left"); cell.VAlign = "Middle"; cell.HAlign = "Left"; // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS row.SetContents(eventMatch, "", dateMatch, zoneMatch, neighborhoodMatch, pricecodeMatch); } var row = myTable.AddRow(); for (var c = 0; c < myTable.Columns.length; c++) { var cell = row.Cells[c]; cell.Font = "GothamHTF-LightCondensed"; cell.PointSize = "10"; row.Cells[0].ShadeColor = "white"; cell.TextColor = "Black"; cell.ShadeColor = "Black"; cell.ShadePct = 15; row.Cells[3].HStraddle = "2" cell.Margins = { Top:40, Bottom:40, Right:500, Left:500 }; cell.SetBorders("Very Thin", "White","Right", "Left"); cell.VAlign = "Middle"; cell.HAlign = "Center"; // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS row.SetContents("", secMatch, rowMatch, seatMatch, "", qtyMatch, "$"+priceMatch, "$"+extendedMatch); } } return myTable.MakeTags(); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 19, 2014 Share Posted September 19, 2014 I have one more issue with this table. There are some fields in my External Data that have ampersands that are giving me an error - Incomplete entity definition Q. I'm having trouble figuring out where to insert a "TaggedTextFromRaw" in my code. I would do it for every call to externalDF.GetFieldValue. For instance: clientMatch.push(TaggedTextFromRaw(externalDF.GetFieldValue(i, 'USERACCOUNTNUMBER'))); Or, you could do it when you're setting the contents in the table. For instance: row.SetContents(TaggedTextFromRaw(eventMatch[i]), "", TaggedTextFromRaw(dateMatch[i]), TaggedTextFromRaw(zoneMatch[i]), TaggedTextFromRaw(neighborhoodMatch[i]), TaggedTextFromRaw(pricecodeMatch[i])); Quote Link to comment Share on other sites More sharing options...
Susan Posted September 19, 2014 Author Share Posted September 19, 2014 Thanks again Dan. 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.