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 April 22nd, 2020, 02:32 PM
bkurzbuch bkurzbuch is offline
Regular Contributor
 
Join Date: May 2014
Posts: 115
Default Table Formatting Help

Coding my first table from scratch and need some advice. Mac - 10.14.6, FP 10.1.11 and latest Acrobat DC. I've attached a zip file of the job to help. There is a pdf labeled customer original to show what the output should be. The table is 4 columns and no more than 17 rows. The data file is imported, not XDF and the data for the table is set up in cell by cell and row by row. You'll see in my template that I have the first row formatted, except for adjusting margins and alignment to match the sample. Since I am finding myself repeating a lot of code, thought i would ask for help. This will be a monthly job so I'm trying to cover all the bases right out of the box. Is there a way to copy all that formatting to the rest of the rows? It will be the same as row zero. My coding skills are minimal at best. My other question is if there is no data can i just use the skip row function or is there a better way. For once I have a few days on this and am using it as a good learning tool, so if you can just point me in the right direction instead of coding for me that would be great. As always thanks for the help.
Attached Files
File Type: zip Table_Advise.zip (617.1 KB, 11 views)
Reply With Quote
  #2  
Old April 23rd, 2020, 07:54 AM
sschardan sschardan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: St. Louis, MO
Posts: 101
Default Re: Table Formatting Help

Use a loop to build the table, and insert a break tag to break out of the loop if a field is empty.


for (var i = 0; i <= 16; i++)

{
var FieldToUse = (i + 1)

if (Field("Item " + FieldToUse) == "" )

break;

insert your table structure here

}
Reply With Quote
  #3  
Old April 23rd, 2020, 07:58 AM
sschardan sschardan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: St. Louis, MO
Posts: 101
Default Re: Table Formatting Help

I should say, insert your cell structure here, not your table structure. Your table structure is defined ahead of the loop
Reply With Quote
  #4  
Old April 23rd, 2020, 09:37 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,598
Default Re: Table Formatting Help

Trying very hard to not just code it for you...

Yes, a "for" loop is your friend here.

Instead of a single call to myTable.AddRows() at the top, you want to call myTable.AddRow() in the loop. If there's no row to add, just continue and skip the call to AddRow for that iteration of the loop.

In other words, don't think of it as skipping rows that you've already added. Instead, think of it as adding rows one at a time, as needed.

So, the whole rule should only be a few lines of code, with a loop that calls myTable.AddRow() and row.SetContents() in it.
__________________
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
  #5  
Old April 23rd, 2020, 10:15 AM
bkurzbuch bkurzbuch is offline
Regular Contributor
 
Join Date: May 2014
Posts: 115
Default Re: Table Formatting Help

Thank You all for the quick Reply. I'm Familiar with "for loop" concept just not how to code it. Thanks Dan. i know its hard not to code it. i have a couple of question already, but I'm going to work with this today and see what other questions arise. It may come to helping with the code as I can learn just by see what it should be. Also thanks for the JavaScript Table API – The Basics post. This was a huge help in getting me started. thanks again
Reply With Quote
  #6  
Old April 23rd, 2020, 02:22 PM
bkurzbuch bkurzbuch is offline
Regular Contributor
 
Join Date: May 2014
Posts: 115
Default Re: Table Formatting Help

Is it just me or does ever complex variable jobs information common in bits and pieces as you work on it. Ugh. Ok - Off the soap box. Uncle, Help!! I've tried unsuccessfully to incorporate the loop. Kinda flying blind when i don't understand the code. My updated code is below. This output the first row perfectly matching the customer originals. Now to get the rest to fill. Now the wrinkle. The data runs out to 20 rows. There 2 different triggers to not include a row. 1. data is blank for that row. 2. The "Disc" field is zero. Now if you cycle through the data you will see that some of the "Disc" lines say "Number 0". This is bad data and we want to show it like this so the customer can see there data needs to be cleaned up. There is also other spelling error and such, all of which they need to see. And of course the due data is moved to Monday. Thanks for all the help. Code away.

Code:
new FPTable;
var myTable = new FPTable;
myTable.AddColumns(5760, 21168, 4536, 4536);  
myTable.AddRows(17);

myTable.Rows[0].Cells[0].SetBorders("Thin", "Black", "Bottom");
myTable.Rows[0].Cells[0].Margins = new FPTableMargins;
myTable.Rows[0].Cells[0].Margins.Top = 25;
myTable.Rows[0].Cells[0].Margins.Bottom = 25;
myTable.Rows[0].CopyCells(0, 1,2,3);

myTable.Rows[0].Cells[0].Margins = new FPTableMargins;
myTable.Rows[0].Cells[0].Margins.Top = 25;
myTable.Rows[0].Cells[0].Margins.Bottom = 25;
myTable.Rows[0].Cells[0].Margins.Left = 350;
myTable.Rows[0].CopyCells(0, 1);

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[0].Font="News Gothic Bold";
myTable.Rows[0].Cells[0].PointSize=6;
myTable.Rows[0].Cells[1].Font="News Gothic Regular";
myTable.Rows[0].Cells[1].PointSize=7;
myTable.Rows[0].Cells[2].Font="News Gothic Bold";
myTable.Rows[0].Cells[2].PointSize=7;
myTable.Rows[0].Cells[3].Font="News Gothic Regular";
myTable.Rows[0].Cells[3].PointSize=7;

myTable.Rows[0].SetContents(Field("Item 1"), Field("Desc 1"), Field("Disc 1"), Field("Price 1"));

return myTable.MakeTags();
Reply With Quote
  #7  
Old April 23rd, 2020, 04:43 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,598
Default Re: Table Formatting Help

Quote:
Originally Posted by bkurzbuch View Post
Uncle, Help!! I've tried unsuccessfully to incorporate the loop. Kinda flying blind when i don't understand the code. My updated code is below. This output the first row perfectly matching the customer originals. Now to get the rest to fill. Now the wrinkle. The data runs out to 20 rows.
Like I said:
Quote:
Originally Posted by Dan Korn View Post
Instead of a single call to myTable.AddRows() at the top, you want to call myTable.AddRow() in the loop.
Following that, the rule with the loop would look like so:
Code:
var myTable = new FPTable;
myTable.AddColumns(5760, 21168, 4536, 4536);  
//myTable.AddRows(17);

for (var i = 1; i <= 20; i++)
{
    var row = myTable.AddRow();
    
    var cell = row.Cells[0];
    cell.SetBorders("Thin", "Black", "Bottom");
    cell.Margins = new FPTableMargins;
    cell.Margins.Top = 25;
    cell.Margins.Bottom = 25;
    row.CopyCells(0, 1,2,3);

    cell.Margins = new FPTableMargins;
    cell.Margins.Top = 25;
    cell.Margins.Bottom = 25;
    cell.Margins.Left = 350;
    row.CopyCells(0, 1);

    row.Cells[0].HAlign = "Left";
    row.Cells[1].HAlign = "Left";
    row.Cells[2].HAlign = "Center";
    row.Cells[3].HAlign = "Center";

    row.Cells[0].Font = "News Gothic Bold";
    row.Cells[0].PointSize = 6;
    row.Cells[1].Font = "News Gothic Regular";
    row.Cells[1].PointSize = 7;
    row.Cells[2].Font = "News Gothic Bold";
    row.Cells[2].PointSize = 7;
    row.Cells[3].Font = "News Gothic Regular";
    row.Cells[3].PointSize = 7;

    row.SetContents(Field("Item " + i), Field("Desc " + i), Field("Disc " + i), Field("Price " + i));
}

return myTable.MakeTags();
Now the other wrinkle is when to suppress rows:
Quote:
Originally Posted by bkurzbuch View Post
There 2 different triggers to not include a row. 1. data is blank for that row. 2. The "Disc" field is zero.
Like I also said:
Quote:
Originally Posted by Dan Korn View Post
If there's no row to add, just continue and skip the call to AddRow for that iteration of the loop.
So, taking that sentence of pseudocode and putting it into code:
Code:
var myTable = new FPTable;
myTable.AddColumns(5760, 21168, 4536, 4536);  

for (var i = 1; i <= 20; i++)
{
    var item = Field("Item " + i);
    var desc = Field("Desc " + i);
    var disc = Field("Disc " + i);
    var price = Field("Price " + i);

    // There 2 different triggers to not include a row.
    // 1. data is blank for that row.
    if (!item && !desc && !disc && !price)
        continue;
        
    // 2. The "Disc" field is zero.
    if (Int(disc) == 0)
        continue;

    var row = myTable.AddRow();
    
    var cell = row.Cells[0];
    cell.SetBorders("Thin", "Black", "Bottom");
    cell.Margins = new FPTableMargins;
    cell.Margins.Top = 25;
    cell.Margins.Bottom = 25;
    row.CopyCells(0, 1,2,3);

    cell.Margins = new FPTableMargins;
    cell.Margins.Top = 25;
    cell.Margins.Bottom = 25;
    cell.Margins.Left = 350;
    row.CopyCells(0, 1);

    row.Cells[0].HAlign = "Left";
    row.Cells[1].HAlign = "Left";
    row.Cells[2].HAlign = "Center";
    row.Cells[3].HAlign = "Center";

    row.Cells[0].Font = "News Gothic Bold";
    row.Cells[0].PointSize = 6;
    row.Cells[1].Font = "News Gothic Regular";
    row.Cells[1].PointSize = 7;
    row.Cells[2].Font = "News Gothic Bold";
    row.Cells[2].PointSize = 7;
    row.Cells[3].Font = "News Gothic Regular";
    row.Cells[3].PointSize = 7;

    row.SetContents(item, desc, disc, price);
}

return myTable.MakeTags();
The code to set all the other attributes of the cells, like the font, size, margins, etc., could be reduced and made a bit more succinct as well, but it's fine as is. I can also tease some of the new form rules in the upcoming FP 11.1 release that will enable you to define a lot of that stuff in a UI instead of having to do it in code.
__________________
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
  #8  
Old April 24th, 2020, 09:43 AM
bkurzbuch bkurzbuch is offline
Regular Contributor
 
Join Date: May 2014
Posts: 115
Default Re: Table Formatting Help

Thank You Dan. I see where I was inserting my code incorrectly. I wasn't adding the 4 fields in the correct spot. Thanks again for all your help. Invaluable!!
If you don't mind. Can you explain the comments below I've added so i get a better understanding of this code.




Code:
var myTable = new FPTable;
myTable.AddColumns(5760, 21168, 4536, 4536);  

for (var i = 1; i <= 20; i++)  Var i=1  What does i mean or denote? 
the next <=20: i++)this tells it to loop trhough 20 lines, but what does i++ mean or denote.
{
    var item = Field("Item " + i);
    var desc = Field("Desc " + i);
    var disc = Field("Disc " + i);
    var price = Field("Price " + i);

    // There 2 different triggers to not include a row.
    // 1. data is blank for that row.
    if (!item && !desc && !disc && !price)
        continue;
        
    // 2. The "Disc" field is zero.
    if (Int(disc) == 0)
        continue;

    var row = myTable.AddRow();
    
    var cell = row.Cells[0];
    cell.SetBorders("Thin", "Black", "Bottom");
    cell.Margins = new FPTableMargins;
    cell.Margins.Top = 25;
    cell.Margins.Bottom = 25;
    row.CopyCells(0, 1,2,3);

    cell.Margins = new FPTableMargins;
    cell.Margins.Top = 25;
    cell.Margins.Bottom = 25;
    cell.Margins.Left = 350;
    row.CopyCells(0, 1);

    row.Cells[0].HAlign = "Left";
    row.Cells[1].HAlign = "Left";
    row.Cells[2].HAlign = "Center";
    row.Cells[3].HAlign = "Center";

    row.Cells[0].Font = "News Gothic Bold";
    row.Cells[0].PointSize = 6;
    row.Cells[1].Font = "News Gothic Regular";
    row.Cells[1].PointSize = 7;
    row.Cells[2].Font = "News Gothic Bold";
    row.Cells[2].PointSize = 7;
    row.Cells[3].Font = "News Gothic Regular";
    row.Cells[3].PointSize = 7;

    row.SetContents(item, desc, disc, price);
}

return myTable.MakeTags();
Reply With Quote
  #9  
Old April 24th, 2020, 10:23 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,598
Default Re: Table Formatting Help

Quote:
Originally Posted by bkurzbuch View Post
Thank You Dan. I see where I was inserting my code incorrectly. I wasn't adding the 4 fields in the correct spot. Thanks again for all your help. Invaluable!!
Glad to help!
Quote:
Originally Posted by bkurzbuch View Post
If you don't mind. Can you explain the comments below I've added so i get a better understanding of this code.
[CODE]
for (var i = 1; i <= 20; i++) Var i=1 What does i mean or denote?
the next <=20: i++)this tells it to loop trhough 20 lines, but what does i++ mean or denote.
/CODE]
A JavaScript for statement has four parts: an initial expression (var i = 1), a condition (i <= 20), an increment expression (i++), and a statement block (the code in brackets, or a single statement, after the "for" line).

The two plus signs are the increment operator. So "i++" simply means, "add one to i." In this case, it adds one for every iteration of the loop.

If you didn't have the i++ there to increment i (and no other code in the statement block to change its value), the value of i would never change, and would stay at 1, and since the loop says to continue as long as i is less than or equal to 20, it would effectively be an infinite loop.

While writing a "for" loop this way, with a single "counter" variable and the ++ operator, is by far the most common usage, you aren't just limited to "add one to the counter variable." You could do something like this to increment backwards:
Code:
for (var i = 20; i >= 1; i--)
Where -- is, of course, the decrement operator, just like the increment operator, but it substracts one each time.

Or you could do something like increment by two (and only deal with odd or even numbers, depending where you start:
Code:
for (var i = 0; i <= 20; i += 2)
There are more advanced things you can do also. For instance, you don't have to reference the same variable in the initial, condition, and increment parts of the loop. And sometimes a different kind of loop is better, such as a while or do..while statement, or even a for...in loop. (In fact, any "for" loop could be rewritten as a "while" loop.) You can read more about different kinds of loops and iteration here:
https://developer.mozilla.org/en-US/..._and_iteration
__________________
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
  #10  
Old April 24th, 2020, 10:50 AM
bkurzbuch bkurzbuch is offline
Regular Contributor
 
Join Date: May 2014
Posts: 115
Default Re: Table Formatting Help

Thank You SOOOO much for your time.
NOW it makes since to me.
thanks again and stay safe Obi-Wan
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 10:12 AM.


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