Jump to content

Suppression Help With Table


dreimer

Recommended Posts

So, below is a sampling of the code for the table I am trying to create. I have some Hard Coded text that I only want to appear when the data field for that row is not empty. Can anyone help me out? TIA

 

new FPTable;
var myTable = new FPTable;
myTable.AddColumns(4800, 28800, 4800);
myTable.AddRows(4);
myTable.Rows[0].Cells[0].SetBorders("Thin","Black","Top","Bottom","Right","Left");
myTable.Rows[0].CopyCells(0,1,2);
myTable.Rows[0].Cells[0].HAlign = "Center";
myTable.Rows[0].SetContents("AB", "Apple Computers & Monitors 48 x 8", Field("Apple Computers & Monitors"));
myTable.Rows[1].Cells[0].Margins = new FPTableMargins;
myTable.Rows[1].Cells[0].Margins.Top = 40;
myTable.Rows[1].Cells[0].Margins.Bottom = 40;
myTable.Rows[1].Cells[0].SetBorders("Thin","Black","Top","Bottom","Right","Left");
myTable.Rows[1].CopyCells(0,1,2);
myTable.Rows[1].Cells[0].HAlign = "Center";
myTable.Rows[1].SetContents("AC", "Audio/Video Accessories 48 x 8", Field("Audio/Video Accessories"));
myTable.Rows[2].Cells[0].SetBorders("Thin","Black","Top","Bottom","Right","Left");
myTable.Rows[2].CopyCells(0,1,2);
myTable.Rows[2].Cells[0].HAlign = "Center";
myTable.Rows[2].SetContents("AD", "Audio/Video Cables 48 x 8", Field("Audio/Video Cables"));
myTable.Rows[3].Cells[0].SetBorders("Thin","Black","Top","Bottom","Right","Left");
myTable.Rows[3].CopyCells(0,1,2);
myTable.Rows[3].Cells[0].HAlign = "Center";
myTable.Rows[3].SetContents("AE", "Automotive & Handheld GPS 48 x 8", Field("Automotive & Handheld GPS"));

Link to comment
Share on other sites

Are you wanting the entire row to "collapse" if the field is empty? If so, this may work for you:

 


var fields = [["AB","Apple Computers & Monitors 48 x 8",Field("Apple Computers & Monitors")],["AC", "Audio/Video Accessories 48 x 8", Field("Audio/Video Accessories")],["AD","Audio/Video Cables 48 x 8", Field("Audio/Video Cables")],["AE","Automotive & Handheld GPS 48 x 8", Field("Automotive & Handheld GPS"]];

var myTable = new FPTable;
myTable.AddColumns(4800, 28800, 4800);
myTable.AddRows(4);

for (var i=0; i<4; i++) {
   if (fields[i][2] != "") {
       myTable.Rows[i].Cells[0].SetBorders("Thin","Black","Top","Bottom","Right","Left");
       myTable.Rows[i].CopyCells(0,1,2);
       myTable.Rows[i].Cells[0].HAlign = "Center";
       myTable.Rows[i].SetContents(fields[i][0], fields[i][1], fields[i][2]);
   }
}

return myTable.MakeTags();

Link to comment
Share on other sites

OK, so now I am told that the fields that I had harcoded will change each time I would want to do this. The first hardcoded "AB" can be ignored for my next question. The second hardcoded part is from the header record and that I would like to have in my table and then each record in my data may have that component or not and that would be inserted into the table. I have attached an example of what I am trying. I also attached a sampling of the data. Is there a way to place the header for each record in my table when there is a quantity of that component and suppress that row in the example if there isn't a quantity? As you can see, I only posted a part of it, I could have alot more rows then 4.

Example.pdf

Test.txt

Edited by dreimer
Link to comment
Share on other sites

OK, so now I am told that the fields that I had harcoded will change each time I would want to do this. The first hardcoded "AB" can be ignored for my next question. The second hardcoded part is from the header record and that I would like to have in my table and then each record in my data may have that component or not and that would be inserted into the table. I have attached an example of what I am trying. I also attached a sampling of the data. Is there a way to place the header for each record in my table when there is a quantity of that component and suppress that row in the example if there isn't a quantity? As you can see, I only posted a part of it, I could have alot more rows then 4.

Since all of the data, including the "headers" (field names) is already in your data file, I would open it with ExternalDataFileEx and iterate. This builds upon Ste's excellent solution to do just that:

var XDF = new ExternalDataFileEx("test.txt", "\t");
var firstItemColumn = 21; // "Apple Computers & Monitors"

var myTable = new FPTable;
myTable.AddColumns(4800, 28800, 4800);
for (var row = firstItemColumn; row <= XDF.fieldCount; row++)
{
   var itemCount = Int(XDF.GetFieldValue(CurrentRecordNumber(), row));
   if (itemCount)
   {
       var thisRow = myTable.AddRow();
       for (var cell = 0; cell < myTable.Columns.length; cell++)
       {
           var thisCell = thisRow.Cells[cell];
           thisCell.SetBorders("Thin","Black","Top","Bottom","Right","Left");
           thisCell.HAlign = "Center";
           thisCell.Margins = { Top:40, Bottom:40 };
       }
       thisRow.SetContents(row, XDF.GetFieldValue(0, row) + " 48 x 8", itemCount);
   }
}
return myTable.MakeTags();

The first column is simply the numeric index of the column in the data file, but a little bit of JavaScript magic could turn that into the alphabetic column designations that Excel uses.

Link to comment
Share on other sites

Thanks for the help on that code Dan. I was wondering now how to edit the last line.

thisRow.SetContents(row, XDF.GetFieldValue(0, row) + " 48 x 8", itemCount);

 

I am going to have them feed me the data I need for the table in one field, for example: "AC_Apple Computers & Monitors_48 x 8". So then I want the first column to have "AC", the next column to have "Apple Computers & Monitors_48 x 8". I have tried to write this but am having trouble. So I want the second column to have everything in the header field except the "AC_" and that number of characters could vary greatly.

thisRow.SetContents(Left(XDF.GetFieldValue(0, row),2), Right(XDF.GetFieldValue(0, row),-3), itemCount);

 

Sorry think I got it now.

 

thisRow.SetContents(Left(XDF.GetFieldValue(0, row),2), Mid(XDF.GetFieldValue(0, row),4,50), itemCount);

Edited by dreimer
Link to comment
Share on other sites

Thanks for the help on that code Dan. I was wondering now how to edit the last line.

thisRow.SetContents(row, XDF.GetFieldValue(0, row) + " 48 x 8", itemCount);

I am going to have them feed me the data I need for the table in one field, for example: "AC_Apple Computers & Monitors_48 x 8". So then I want the first column to have "AC", the next column to have "Apple Computers & Monitors_48 x 8". I have tried to write this but am having trouble. So I want the second column to have everything in the header field except the "AC_" and that number of characters could vary greatly.

thisRow.SetContents(Left(XDF.GetFieldValue(0, row),2), Right(XDF.GetFieldValue(0, row),-3), itemCount);

I was basing the logic on the data provided, so it's a little hard to know exactly what to change without seeing the new data file. But if the "prefix" part is always two letters, like "AC", then I think this will work in place of that last line:

        var header = XDF.GetFieldValue(0, row);
       thisRow.SetContents(header.substr(0,2), header.substr(3), itemCount);

Link to comment
Share on other sites

  • 3 weeks later...
Quick question with tables. When I validate my rule, there is a (truncated to 10000 characters) warning. Is this for the validation process or for the composed table itself?

That's just for the Validate dialog, so that it doesn't try to put a huge number of characters in that text box and run out of memory in the GUI. You'll get all the tags for the composed table (or whatever you're returning from the rule).

 

If you really want to see all the tags, you can either uncheck "Treat returned strings as tagged text" and see them in the output, or you can add a line right before the end like "Print(myTable.MakeTags());" and see the markup in the composition log (.msg) file.

Link to comment
Share on other sites

  • 1 year later...

So now I have the same project basically but they want to add a thumbnail image for each row. Is this possible to do in my existing rule using an inline graphic?

 

I was thinking that the header for each would have the name of the image included so that I could still use the current table I have using the External data file.

 

For example: "AC_Apple Computers & Monitors_48 x 8.tiff" as the header.

 

I have uploaded a final product I am trying to get to. So some records would not get all products so I would need to suppress text and image.

Kit AA only.pdf

Edited by dreimer
Link to comment
Share on other sites

You can use inline graphics in a table. It would be easier to help you, though, if you could collect your template and data to give the forum a better understanding of what you're looking to accomplish.
Link to comment
Share on other sites

OK, here is the template I currently use without any inline graphics. So basically if a field is populated with a quantity, it would populate in the table. Was wondering how if possible to incorporate an image with each component as well. I think I could manipulate the data however I would need to. TIA

Table Template.zip

Link to comment
Share on other sites

If you setup your graphics to be named to match the description of the item (which is what it seems like you were saying you wanted to do), you should be able to add another column in your table and populate it with an image of your product by making these changes to your existing code (in red):

var XDF = new ExternalDataFileEx("95069_List.csv", "\,");
var firstItemColumn = 13; // "Apple Computers & Monitors"

var myTable = new FPTable;
myTable.AddColumns([color="red"]4900,[/color]4800, 28800, 4800);
for (var row = firstItemColumn; row <= XDF.fieldCount; row++)
{
   var itemCount = Int(XDF.GetFieldValue(CurrentRecordNumber(), row));
   if (itemCount)
   {
       var thisRow = myTable.AddRow();
       for (var cell = 0; cell < myTable.Columns.length; cell++)
       {
           var thisCell = thisRow.Cells[cell];
           thisCell.SetBorders("Thin","Black","Top","Bottom","Right","Left");
           thisCell.HAlign = "Center";
           thisCell.Margins = { Top:40, Bottom:40 };
       }
       var header = XDF.GetFieldValue(0, row);
       thisRow.SetContents([color="Red"]'<graphic file="/path/to/graphics/' + header.substr(3) + '.tiff" width="4100">', [/color]header.substr(0,2), header.substr(3), itemCount);
   }
}
return myTable.MakeTags();

Link to comment
Share on other sites

  • 4 months later...

So I am trying to change this table rule to also include a header for my three columns. I had originally just had the headers for each column above my table in text boxes. Well now some of these tables are getting larger and I need overflow pages to also have the header. Can I add a header to the table rule? Below is my current code. TIA

 

var XDF = new ExternalDataFileEx("84384_List.csv", "\,");
var firstItemColumn = 11; // "Apple Computers & Monitors"
var myTable = new FPTable;
myTable.AddColumns(4800, 31200, 4800);
for (var row = firstItemColumn; row <= XDF.fieldCount; row++)
{
   var itemCount = Int(XDF.GetFieldValue(CurrentRecordNumber(), row));
   if (itemCount)
   {
       var thisRow = myTable.AddRow();
       for (var cell = 0; cell < myTable.Columns.length; cell++)
       {
           var thisCell = thisRow.Cells[cell];
           thisCell.SetBorders("Thin","Black","Top","Bottom","Right","Left");
           thisCell.HAlign = "Center";
           thisCell.Margins = { Top:40, Bottom:40 };
       }
       var header = XDF.GetFieldValue(0, row);
       thisRow.SetContents(header.substr(0,2), header.substr(3), itemCount);
   }
}
return myTable.MakeTags();

Link to comment
Share on other sites

So I changed my rule to this. I get the header but I then lose my first row of data. Any Ideas how to fix?

 

var XDF = new ExternalDataFileEx("84384_List.csv", "\,");
var firstItemColumn = 11; // "Apple Computers & Monitors"
var myTable = new FPTable;
myTable.AddColumns(4800, 31200, 4800);
for (var row = firstItemColumn; row <= XDF.fieldCount; row++)
{
   var itemCount = Int(XDF.GetFieldValue(CurrentRecordNumber(), row));
   if (itemCount)
   {
       var thisRow = myTable.AddRow();
       for (var cell = 0; cell < myTable.Columns.length; cell++)
       {
           var thisCell = thisRow.Cells[cell];
           thisCell.SetBorders("Thin","Black","Top","Bottom","Right","Left");
           thisCell.HAlign = "Center";
           thisCell.Margins = { Top:40, Bottom:40 };
       }
       var header = XDF.GetFieldValue(0, row);
       thisRow.SetContents(header.substr(0,2), header.substr(3), itemCount);
   }
}
[color=red]myTable.Rows[0].Type = "Header";[/color]

[color=red]myTable.Rows[0].Cells[0].Font = "Myriad Pro Black";
myTable.Rows[0].Cells[0].PointSize = 12;
myTable.Rows[0].Cells[0].Content = "CODE";
myTable.Rows[0].Cells[1].Font = "Myriad Pro Black";
myTable.Rows[0].Cells[1].PointSize = 12;
myTable.Rows[0].Cells[1].Content = "DESCRIPTION";
myTable.Rows[0].Cells[2].Font = "Myriad Pro Black";
myTable.Rows[0].Cells[2].PointSize = 12;
myTable.Rows[0].Cells[2].Content = "QTY";[/color]

return myTable.MakeTags();

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