Jump to content

Table - how to remove extra blank rows


Susan

Recommended Posts

I am creating a basic table but I can't figure out why I am getting extra blank rows on the top and the bottom of the table. I think it is this code — "myTable.AddRows(clientMatch.length+2);" — but if I remove it the table won't validate. The table rule is below. Files are attached also.

 

 

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 duedateMatch = [];

var descriptionMatch = [];

var chargeMatch = [];

var creditMatch = [];

 

 

// 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, 'ContractNumberFormat') == Field("ContractNumberFormat")){

clientMatch.push(externalDF.GetFieldValue(i, 'ContractNumberFormat'));

duedateMatch.push(externalDF.GetFieldValue(i, 'duedate'));

descriptionMatch.push(externalDF.GetFieldValue(i, 'transactioncodedescription'));

chargeMatch.push(externalDF.GetFieldValue(i, 'charge'));

creditMatch.push(externalDF.GetFieldValue(i, 'credit'));

 

}

}

 

/*=============================================================================

|| Create the table

||=============================================================================*/

new FPTable;

var myTable = new FPTable;

myTable.AddColumns(6600, 27200, 10200,7400)

myTable.AddRows(clientMatch.length+2); // add 2 additional rows (Header and summary lines)

 

 

// 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 = "Arial SF MT";

myTable.Rows.Cells[0].PointSize = "9";

myTable.Rows.Cells[0].TextColor = "Black";

myTable.Rows.Cells[0].Margins = new FPTableMargins;

myTable.Rows.Cells[0].Margins.Top = 5;

myTable.Rows.Cells[0].Margins.Bottom = 5;

myTable.Rows.Cells[0].Margins.Right = 200;

myTable.Rows.Cells[0].Margins.Left = 200;

myTable.Rows.CopyCells(0,1,2,3); // Apply the same formating to each cell in this row

 

 

// CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS

myTable.Rows.Cells[0].HAlign = "Left";

myTable.Rows.Cells[1].HAlign = "Left";

myTable.Rows.Cells[2].HAlign = "Right";

myTable.Rows.Cells[3].HAlign = "Right";

myTable.Rows.SetContents(duedateMatch[i-1], descriptionMatch[i-1], chargeMatch[i-1], creditMatch[i-1]);

 

}

return myTable.MakeTags();

 

 

 

Thanks for any help.

for Forum.zip

Link to comment
Share on other sites

Susan

This should work for you:

 

 

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 duedateMatch = [];

var descriptionMatch = [];

var chargeMatch = [];

var creditMatch = [];

 

 

// 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, 'ContractNumberFormat') == Field("ContractNumberFormat")){

clientMatch.push(externalDF.GetFieldValue(i, 'ContractNumberFormat'));

duedateMatch.push(externalDF.GetFieldValue(i, 'duedate'));

descriptionMatch.push(externalDF.GetFieldValue(i, 'transactioncodedescription'));

chargeMatch.push(externalDF.GetFieldValue(i, 'charge'));

creditMatch.push(externalDF.GetFieldValue(i, 'credit'));

 

}

}

 

/*=============================================================================

|| Create the table

||=============================================================================*/

new FPTable;

var myTable = new FPTable;

myTable.AddColumns(6600, 27200, 10200,7400)

myTable.AddRows(1);

myTable.Rows[0].Type = "Header";

myTable.Rows[0].Cells[0].Font = "Arial SF MT";

myTable.Rows[0].Cells[0].PointSize = "9";

myTable.Rows[0].Cells[0].TextColor = "Black";

myTable.Rows[0].Cells[0].Margins = new FPTableMargins;

myTable.Rows[0].Cells[0].Margins.Top = 5;

myTable.Rows[0].Cells[0].Margins.Bottom = 5;

myTable.Rows[0].Cells[0].Margins.Right = 200;

myTable.Rows[0].Cells[0].Margins.Left = 200;

myTable.Rows[0].Cells[0].HAlign = "Left";

myTable.Rows[0].Cells[1].HAlign = "Left";

myTable.Rows[0].Cells[2].HAlign = "Right";

myTable.Rows[0].Cells[3].HAlign = "Right";

myTable.Rows[0].SetContents(duedateMatch[0], descriptionMatch[0], chargeMatch[0], creditMatch[0]);

 

 

// interate through the length of the arrays (data matches from external data file) and create rows

for (var k=0; k<=clientMatch.length-1; k++) {

// TABLE CONTENT FORMATTING

myTable.AddRows(1);

myTable.Rows[k].Cells[0].Font = "Arial SF MT";

myTable.Rows[k].Cells[0].PointSize = "9";

myTable.Rows[k].Cells[0].TextColor = "Black";

myTable.Rows[k].Cells[0].Margins = new FPTableMargins;

myTable.Rows[k].Cells[0].Margins.Top = 5;

myTable.Rows[k].Cells[0].Margins.Bottom = 5;

myTable.Rows[k].Cells[0].Margins.Right = 200;

myTable.Rows[k].Cells[0].Margins.Left = 200;

myTable.Rows[k].CopyCells(0,1,2,3); // Apply the same formating to each cell in this row

 

 

// CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS

myTable.Rows[k].Cells[0].HAlign = "Left";

myTable.Rows[k].Cells[1].HAlign = "Left";

myTable.Rows[k].Cells[2].HAlign = "Right";

myTable.Rows[k].Cells[3].HAlign = "Right";

myTable.Rows[k].SetContents(duedateMatch[k], descriptionMatch[k], chargeMatch[k], creditMatch[k]);

 

 

}

return myTable.MakeTags();

Link to comment
Share on other sites

Yes, the idea here is that you don't need to suppress any table rows. Instead, you only put out the table rows as needed.

 

The rule can be further simplified/reduced to this, without the need for a separate OnJobStart rule:

var externalDF = new ExternalDataFileEx("external data.txt");
if (!externalDF.valid)
   throw 'Failed to link to the external data file';

var XDF_rows = externalDF.FindRecords("ContractNumberFormat", Field("ContractNumberFormat"));

var myTable = new FPTable;
myTable.AddColumns(6600, 27200, 10200, 7400);

for (var i in XDF_rows)
{
   var r = XDF_rows[i];
   var row = myTable.AddRow();

   // TABLE CONTENT FORMATTING 
   var cell0 = row.Cells[0];
   cell0.Font = "Arial SF MT";
   cell0.PointSize = "9";
   cell0.TextColor = "Black";
   cell0.Margins = { Top:5, Bottom:5, Right:200, Left:200 };
   cell0.HAlign = "Left";
   row.CopyCells(0,1,2,3); // Apply the same formating to each cell in this row
   row.Cells[2].HAlign = "Right";
   row.Cells[3].HAlign = "Right";

   // CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS    
   var XDF_fieldsToShow = ['duedate', 'transactioncodedescription', 'charge', 'credit'];
   var vals = XDF_fieldsToShow.map(function(name){return externalDF.GetFieldValue(r, name);});
   row.SetContents.apply(row, vals);
}

return myTable.MakeTags();

This takes advantage of several new features in FusionPro 9.3, specifically:

  • XDFs are automatically cached, so that calling new ExternalDataFileEx repeatedly for the same file in a regular per-record rule doesn't incur any penalty, and you no longer need to open them in OnJobStart.
  • You no longer have to specify the delimiter for a flat-file XDF. FusionPro will detect it in most cases.
  • The new ExternalDataFileEx.FindRecords function returns an array of all the row numbers in the XDF where a specified XDF field matches a specified value. So you don't need to iterate the XDF, just the array of row numbers.

I'm also using a couple of JavaScript tricks with Array.map and function.apply to populate the cells in the table row from a simple array of XDF field names.

Link to comment
Share on other sites

Thank you! Both the solutions worked great.

 

I was having one more issue though when I was testing overflow pages. I got the warning "Table width exceeds column width; table may set outside frame." The output PDF looks correct but I numbered the "Charge" and "Credit" columns so I would be able to check it and it seems to be skipping number "118" and "218" and going to "119" on the second page. I've tried lengthening my table frame but that didn't work.

 

I'm attaching the multipage FP file.

 

Thanks again for your help.

Multipage.zip

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...