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
  #11  
Old July 26th, 2016, 12:30 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Table / Copyfitting for 1 to 6 fields

Quote:
Originally Posted by jl_arnold View Post
Quick follow up question.

I did this and made the table with 5 locations have 4 columns, where I merged column 2 and 3 in row 1, and the I merged 1 and 2 in row 2, as well as 3 and 4 in row 2.
Oh, gotcha. I was basing my answer off of the image you posted in your second post. That being said, it doesn't sound like you're describing a 4 column table to me. It sounds like a 2 column table wherein the cell in the last row spans both columns.

If that's what you want to do, then you don't need the code to add the blank space before the last element in arrays with a length of 5. It sounds to me like you can also modify the line for determining the number of columns to say "if the length of the array of populated fields is evenly divisible by 3 ( fields.length % 3 ), then make a 3 column table – otherwise make a two column table". Then when you're making your table just add a line that straddles the last cell of a row. That way, if one field is populated it will straddle 2 columns giving the appearance of 1 column. The same will be true for a scenario where 5 fields are populated.

Revised code below:
Code:
var fields = [Field("Location 1"), Field("Location 2"), Field("Location 3"), Field("Location 4"), Field("Location 5"), Field("Location 6")].filter(String);
  
// Determine the number of columns
var cols = fields.length % 3 ? 2 : 3;
var tableWidth = 32328;

var myTable = new FPTable();
for (var i=0; i<cols; i++)
  myTable.AddColumn(tableWidth/cols);

while(fields.length) {
  var row = myTable.AddRow();
  for (var i=0; i<cols; i++) {
    var cell = row.Cells[i];
    cell.HAlign = 'Center';
    cell.Content = fields.shift();
    if (!fields.length) cell.HStraddle = 2; // Straddle 2 columns on the last element.
  }
}

return myTable.MakeTags();
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #12  
Old July 26th, 2016, 12:58 PM
tou tou is offline
Regular Contributor
 
Join Date: Oct 2015
Posts: 107
Default Re: Table / Copyfitting for 1 to 6 fields

I'm getting the attached results for 5 location testing.

Cool!
Attached Images
File Type: png 2016-07-26 14_34_46-columns test.png (1.4 KB, 7 views)
Reply With Quote
  #13  
Old July 26th, 2016, 01:10 PM
jl_arnold jl_arnold is offline
Regular Contributor
 
Join Date: Jun 2016
Posts: 53
Default Re: Table / Copyfitting for 1 to 6 fields

I was getting something similar. I ended up going with the rule to require sequential ordering for Locations 1 through 6 for now.

I want to also be able to copyfit and since I had added point sizes for the cell references, I felt I had a little more control with the more basic code.

I was going to do additional testing for copyfit. Step, I'm going to test that on your original code since that is limited to two rows.

Thanks again guys!


PS. I meant to include a view of what my current "incremental" code displays as.
https://images.printable.com/imageli...eTextTable.jpg

Last edited by jl_arnold; July 26th, 2016 at 01:13 PM.. Reason: Meant to include an image
Reply With Quote
  #14  
Old July 27th, 2016, 07:11 AM
tou tou is offline
Regular Contributor
 
Join Date: Oct 2015
Posts: 107
Default Re: Table / Copyfitting for 1 to 6 fields

Looks like you'll have to code 2 rules....

Rule # 1 - line1
Rule # 2 - line2


line1 (var a,b,c,d,e,f are for testing only and should point to your field - I've used static strings for testing)
Code:
var a="A"
var b=""
var c="C"
var d="D"
var e="E"
var f="F"

var fields = [a,b,c,d,e,f].filter(String);

var myTable = new FPTable;

if (fields.length == 1)
    var cols = 1
    else if (fields.length == 2)
    var cols = 2
    else if (fields.length == 3)
    var cols = 3
    else if (fields.length == 4)
    var cols = 2
    else if (fields.length == 5)
    var cols = 3
    else 
    var cols = 3

if (cols == 1) {
   myTable.AddColumns(32328);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[0].Content = fields[0];
} else if (cols == 2) {
   myTable.AddColumns(16164, 16164);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[1].HAlign = "Center"; 
   myRow.Cells[0].Content = fields[0];
   myRow.Cells[1].Content = fields[1];
} else {
   myTable.AddColumns(10776, 10776, 10776);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[1].HAlign = "Center"; 
   myRow.Cells[2].HAlign = "Center"; 
   myRow.Cells[0].Content = fields[0];
   myRow.Cells[1].Content = fields[1];
   myRow.Cells[2].Content = fields[2];
}

return myTable.MakeTags();
line 2 (var a,b,c,d,e,f are for testing only and should point to your field - I've used static strings for testing)
Code:
var a="A"
var b=""
var c="C"
var d="D"
var e="E"
var f="F"

var fields = [a,b,c,d,e,f].filter(String);

var myTable = new FPTable;

if (fields.length == 1)
    var cols = 1
    else if (fields.length == 2)
    var cols = 2
    else if (fields.length == 3)
    var cols = 3
    else if (fields.length == 4)
    var cols = 2
    else if (fields.length == 5)
    var cols = 2
    else 
    var cols = 3

if (cols == 1) {
} else if (cols == 2) {
   myTable.AddColumns(16164, 16164);
   var myRow = myTable.AddRow();
   myTable.HAlign = "Center";
   myRow.Cells[0].HAlign = "Center"; 
   myRow.Cells[1].HAlign = "Center";
   if (fields.length == 4) {  
      myRow.Cells[0].Content = fields[2];
      myRow.Cells[1].Content = fields[3];
   } else if (fields.length == 5) {
      myRow.Cells[0].Content = fields[3];
      myRow.Cells[1].Content = fields[4];
   } 
} else {
   if (fields.length > 3) {  
      myTable.AddColumns(10776, 10776, 10776);
      var myRow = myTable.AddRow();
      myTable.HAlign = "Center";
      myRow.Cells[0].HAlign = "Center"; 
      myRow.Cells[1].HAlign = "Center"; 
      myRow.Cells[2].HAlign = "Center"; 
      myRow.Cells[0].Content = fields[3];
      myRow.Cells[1].Content = fields[4];
      myRow.Cells[2].Content = fields[5];
   }
}

return myTable.MakeTags();
In your text box, stack the two variables on top of each other.

Last edited by tou; July 27th, 2016 at 07:16 AM..
Reply With Quote
  #15  
Old July 27th, 2016, 10:00 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Table / Copyfitting for 1 to 6 fields

Quote:
Originally Posted by jl_arnold View Post
I was getting something similar. I ended up going with the rule to require sequential ordering for Locations 1 through 6 for now.
Sorry, I misunderstood what you were going for. Now I understand that you want a top row with 3 columns and the bottom row to have 2 columns if there are 5 populated fields. The only potential issue I see with having 4 columns and joining the second and third cell on the top row is that the resulting cell will be wider than the other two cells on the top row.

Instead of determining the number of columns upfront like I initially suggested, why not create a 6 column table and variably set the straddle (the width of the cell) based on how many elements are in a particular row? This is how I would do that:
Code:
var fields = [Field("Location 1"), Field("Location 2"), Field("Location 3"), Field("Location 4"), Field("Location 5"), Field("Location 6")].filter(String);

var myTable = new FPTable();
myTable.AddColumns(5388,5388,5388,5388,5388,5388);
var cols = Math.ceil((fields.length/2)%2) ? 3 : 2;

while(fields.length) {
  var row = myTable.AddRow();   
  fields.splice(0, cols).forEach(function(s,p,a){
    var span = 6/a.length;
    var cell = row.Cells[p*span];
    cell.HAlign = 'Center';
    cell.HStraddle = span;
    row.Cells[p*span].Content = s;
  });
}

return myTable.MakeTags();
Quote:
Originally Posted by jl_arnold View Post
I want to also be able to copyfit and since I had added point sizes for the cell references, I felt I had a little more control with the more basic code.
I would suggest looking into the CopyfitLine function for that. Since you'll already know the size of the cell based on how many cells it's straddling (5388*span), you'll be able to set up copyfitting for each particular row.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #16  
Old July 27th, 2016, 10:10 AM
tou tou is offline
Regular Contributor
 
Join Date: Oct 2015
Posts: 107
Default Re: Table / Copyfitting for 1 to 6 fields

Sweet. I knew it could be done more concisely!

(¬‿¬)
Reply With Quote
  #17  
Old July 27th, 2016, 10:36 AM
jl_arnold jl_arnold is offline
Regular Contributor
 
Join Date: Jun 2016
Posts: 53
Default Re: Table / Copyfitting for 1 to 6 fields

I like it! It works perfectly!

I'm definitely going to look into the Copyfit function and work on it for each row, but I was able to set the global Copyfit rule to work that way.

Thanks so much for the help!
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 12:02 PM.


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