Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Tables & Charts

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 21st, 2018, 06:11 AM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 56
Default Table - how to remove extra blank rows

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[i].Cells[0].Font = "Arial SF MT";
myTable.Rows[i].Cells[0].PointSize = "9";
myTable.Rows[i].Cells[0].TextColor = "Black";
myTable.Rows[i].Cells[0].Margins = new FPTableMargins;
myTable.Rows[i].Cells[0].Margins.Top = 5;
myTable.Rows[i].Cells[0].Margins.Bottom = 5;
myTable.Rows[i].Cells[0].Margins.Right = 200;
myTable.Rows[i].Cells[0].Margins.Left = 200;
myTable.Rows[i].CopyCells(0,1,2,3); // Apply the same formating to each cell in this row


// 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 = "Right";
myTable.Rows[i].Cells[3].HAlign = "Right";
myTable.Rows[i].SetContents(duedateMatch[i-1], descriptionMatch[i-1], chargeMatch[i-1], creditMatch[i-1]);

}
return myTable.MakeTags();



Thanks for any help.
Attached Files
File Type: zip for Forum.zip (520.9 KB, 11 views)
__________________
FusionPro Creator v10.1.9 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC
Reply With Quote
  #2  
Old June 21st, 2018, 08:43 AM
jwhittaker jwhittaker is offline
Senior Contributor
 
Join Date: Feb 2009
Location: San Diego
Posts: 158
Default Re: Table - how to remove extra blank rows

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();
__________________
FusionPro VDP Creator 10.0.26 | MacOS 10.13.4 | Acrobat DC
Reply With Quote
  #3  
Old June 21st, 2018, 11:04 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,320
Default Re: Table - how to remove extra blank rows

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:
Code:
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.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #4  
Old June 21st, 2018, 12:17 PM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 56
Default Re: Table - how to remove extra blank rows

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.
Attached Files
File Type: zip Multipage.zip (837.5 KB, 1 views)
__________________
FusionPro Creator v10.1.9 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:45 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.