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 July 12th, 2017, 07:34 AM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 56
Default Table rule for straddling columns

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[i].Cells[0].Font = "HelveticaNeueLT Std Cn";
myTable.Rows[i].Cells[0].PointSize = "10";

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

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";
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]);


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]);

}
return myTable.MakeTags();
__________________
FusionPro Creator v10.1.9 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC

Last edited by Susan; July 13th, 2017 at 10:09 AM..
Reply With Quote
  #2  
Old July 13th, 2017, 07:08 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Table rule for straddling columns

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:
Code:
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:
Code:
// 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:
Code:
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";
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]);


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]);
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:
Code:
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

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";
Code:
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].Cells[0].VAlign = "Middle";
myTable.Rows[i].CopyCells(0,1,2,3,4,5,6,7); // Apply the same formating to each cell in this row
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old July 13th, 2017, 08:59 AM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 56
Default Re: Table rule for straddling columns

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[i].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.
__________________
FusionPro Creator v10.1.9 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC
Reply With Quote
  #4  
Old July 13th, 2017, 10:07 AM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 56
Default Re: Table rule for straddling columns

It looks like my file didn't attach. I'll try again.
__________________
FusionPro Creator v10.1.9 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC
Reply With Quote
  #5  
Old July 13th, 2017, 10:10 AM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 56
Default Re: Table rule for straddling columns

Can't seem to get my file to attach. I'll try once more. Got it!
Attached Files
File Type: zip Sample.zip (2.88 MB, 16 views)
__________________
FusionPro Creator v10.1.9 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC
Reply With Quote
  #6  
Old July 13th, 2017, 03:33 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Table rule for straddling columns

Quote:
Originally Posted by Susan View Post
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:
Code:
// 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]);
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];
Quote:
Originally Posted by Susan View Post
On the more versatile code I get an error on this line
Code:
  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:
Code:
// 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]);

// 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;
}
Quote:
Originally Posted by Susan View Post
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:
Code:
// 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;
  // Align text to the left if straddling multiple cells.
  if (straddle > 1) 
    myTable.Rows[i].Cells[c].HAlign = "Left";
}
Or:
Code:
var secCell = myTable.Rows[i].Cells[2];
secCell.HStraddle = 1 + !rowMatch[i-1] + !seatMatch[i-1];
if (secCell.HStraddle > 1)
  secCell.HAlign = "Left";
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #7  
Old July 14th, 2017, 06:10 AM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 56
Default Re: Table rule for straddling columns

Both versions of code are working great. Thanks for all your help and for sharing your knowledge.
__________________
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 02:06 PM.


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