Dan Korn Posted March 28, 2011 Share Posted March 28, 2011 The JavaScript table object in FusionPro 7.0, new FPTable, must be declared at the beginning of a table, followed by the number of columns that the table will use. Columns are defined in 100ths of a point. The example below shows 4 columns that are each an inch wide. The number of rows can be added row by row, or at the beginning of the table. new FPTable; var myTable = new FPTable; myTable.AddColumns(7200, 7200, 7200, 7200); myTable.AddRows(2); At the end of the table, the MakeTags() function must be called: return myTable.MakeTags(); There are 2 ways to set content for the cells. The first row and column in a table is always 0. Text Fields, static type or even graphic images can be placed inside a cell: myTable.Rows[0].Cells[0].Content = "Hello"; myTable.Rows[0].Cells[1].Content = Field("FName"); myTable.Rows[0].Cells[2].Content = "Goodbye"; myTable.Rows[0].Cells[3].Content = Field("LName"); The second way is can also set the content of all the cells in an entire row like this:myTable.Rows[1].SetContents("Hi", Field("FName"), "Bye", Field("LName")); It is possible to copy content and formatting from one cell to another in a row. In the example below, the content is set into cell 2,0 and then copied into cells 2,1 / 2,2 / 2,3. myTable.Rows[2].Cells[0].Content = "Bon Jour"; myTable.Rows[2].CopyCells(0, 1,2,3); In this example, thin Black borders are applied to cell 0,0 and then copied to cells 0,1 / 0,2 / 0,3.myTable.Rows[0].Cells[0].SetBorders("Thin", "Black", "Top", "Bottom", "Right", "Left"); myTable.Rows[0].CopyCells(0, 1,2,3); When copying the formatting of one cell to another, it is important to remember to set the content of the subsequent cells after the formatting is done (unless the content is also meant to be the same). The following pages show more examples of ways to format a cell. Shading: Two properties for Shading are Shade Color and Shade Percent. myTable.Rows[1].Cells[0].ShadeColor="Black"; myTable.Rows[1].Cells[0].ShadePct=20; There are two more properties for Shading which are Shading Repeat and Shading Type. This allows you to specify 2 (or more) different shading values so that you can alternate shading between rows or columns. The two properties for Shading Type are "ByRow" or "ByColumn". myTable.ShadingColor1 = "Blue"; myTable.ShadingPct1 = 20; myTable.ShadingRepeat1 = 1; myTable.ShadingColor2 = "Red"; myTable.ShadingPct2 = 40; myTable.ShadingRepeat2 = 1; myTable.ShadingType = "ByRow"; //or "ByColumn" SetBorders: The 2 border properties include thickness and location. Values for thickness are "Thin", "Medium," "Thick" and "None". If no parameter is specified, the border will default to none. Values for location are "Top," "Bottom," "Right" and "Left". myTable.Rows[0].Cells[0].SetBorders("Thin", "Black", "Top", "Bottom); Font Formatting: The 3 properties for font formatting are Font Face, Text Color and Point Size. myTable.Rows[2].Cells[0].Font="Times New Roman"; myTable.Rows[2].Cells[0].TextColor="Red"; myTable.Rows[2].Cells[0].PointSize=15; Bold/Italics: Below is an example of how to apply Bold and Italic formatting to text in a cell: myTable.Rows[2].Cells[0].Bold="On"; myTable.Rows[2].Cells[0].Italic="On"; Margins: To use table margins, the new FPTableMargins object must be declared. Once the new FPTableMargins object is called, the 4 parameters that can be used are Top, Bottom, Left and Right. The margins for top and bottom are called out in 10ths of a point. For left and right they are called out in 100ths of a point myTable.Rows[2].Cells[0].Margins = new FPTableMargins; myTable.Rows[2].Cells[0].Margins.Top = 50; myTable.Rows[2].Cells[0].Margins.Bottom = 50; Rotation: The contents of a cell can be rotated by using the rotation property. Valid values for rotation are 0, 90, 180, or 270. myTable.Rows[3].Cells[0].Rotate = 90; To combine or merge cells together, HStraddle and VStraddle can be used to straddle cells both Horizontally and Vertically:myTable.Rows[3].Cells[0].HStraddle = 2; myTable.Rows[3].Cells[2].VStraddle = 2; To align content within cells horizontally, the HAlign property can be used with the values of "Left", "Right" and "Center": myTable.Rows[3].Cells[0].HAlign = "Left"; myTable.Rows[3].Cells[1].HAlign = "Right"; myTable.Rows[3].Cells[2].HAlign = "Center"; To align content within cells vertically, the VAlign property can be used with the values of "Top", "Bottom" and "Middle": myTable.Rows[3].Cells[0].VAlign = "Top"; myTable.Rows[3].Cells[1].VAlign = "Bottom"; myTable.Rows[3].Cells[2].VAlign = "Middle"; Advanced Settings: It is possible to specify a row in a table to be a header type and a footer type. When a row is specified as a header or footer, it will repeat on overflow pages. myTable.Rows[0].Type = "Header"; myTable.Rows[4].Type = "Footer"; There is also a way to skip a row in a table if needed. This could be based on some conditional logic.myTable.Rows[0].Type = "Skip"; //removes the row from the table Below is a sample table rule (containing 2 text fields for first and last name) and the resulting output: var myTable = new FPTable; myTable.AddColumns(7200, 7200, 7200, 7200); myTable.AddRows(3); myTable.Rows[0].Cells[0].Font="Times New Roman"; myTable.Rows[0].Cells[0].TextColor="Red"; myTable.Rows[0].Cells[0].SetBorders("Thin", "Black", "Top", "Bottom", "Right", "Left"); myTable.Rows[0].CopyCells(0, 1,2,3); myTable.Rows[0].Cells[0].Content = "Hello"; myTable.Rows[0].Cells[1].Content = Field("FName"); myTable.Rows[0].Cells[2].Content = "Goodbye"; myTable.Rows[0].Cells[3].Content = Field("LName"); myTable.Rows[1].Cells[0].Font="Arial"; myTable.Rows[1].Cells[0].TextColor="Blue"; myTable.Rows[1].Cells[0].SetBorders("Thin", "Black", "Top", "Bottom", "Right", "Left"); myTable.Rows[1].CopyCells(0, 1,2,3); myTable.Rows[1].SetContents( "Hola", Field("FName"), "Adios", Field("LName")); myTable.Rows[2].Cells[0].Font="Times New Roman"; myTable.Rows[2].Cells[0].TextColor="Green"; myTable.Rows[2].Cells[0].SetBorders("Thin", "Black", "Top", "Bottom", "Right", "Left"); myTable.Rows[2].CopyCells(0, 1,2,3); myTable.Rows[2].SetContents( "This", "Row", "is", "Green"); return myTable.MakeTags(); http://forums.printable.com/attachment.php?attachmentid=417&stc=1&d=1301344348 PDF version of this document Quote Link to comment Share on other sites More sharing options...
DSweet Posted March 29, 2011 Share Posted March 29, 2011 Dan, Is there anything in the works about being able to do this simpler form of JavaScript programming to create charts on the fly as well? Thanks . Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 29, 2011 Author Share Posted March 29, 2011 Is there anything in the works about being able to do this simpler form of JavaScript programming to create charts on the fly as well? Not at this time. Chart formats are defined in the Chart Properties GUI, not via tags as tables are, so wrapping that functionality in a JavaScript object is much more complicated. You can use the DIF API to modify chart formats if you're developing with FusionPro Server. What kind of dynamic chart generation are you looking for? If you want to suggest an API or post an example of the kind of code you'd like to be able to write, I can make an enhancement case for it. Quote Link to comment Share on other sites More sharing options...
DSweet Posted March 29, 2011 Share Posted March 29, 2011 We do a lot of 401K and other such financial statements for certain clients. They currently have their information in a table form, but they are telling us that they are looking elsewhere to do this since other companies are telling them they can more visually pleasing and easier to read charts in a smaller area than we can with FusionPro (3D, single slice exploded pie, legend numbers within the chart bars and slices, etc.) Currently I'm just looking to being able to program even the simple charts within FusionPro instead of having to make a separate .txt file for each chart. . Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 29, 2011 Author Share Posted March 29, 2011 We do a lot of 401K and other such financial statements for certain clients. They currently have their information in a table form, but they are telling us that they are looking elsewhere to do this since other companies are telling them they can more visually pleasing and easier to read charts in a smaller area than we can with FusionPro (3D, single slice exploded pie, legend numbers within the chart bars and slices, etc.) Currently I'm just looking to being able to program even the simple charts within FusionPro instead of having to make a separate .txt file for each chart. . If you only want to generate the chart data dynamically, that's easy to do with JavaScript. You don't need a .txt file at all. The tagging for a chart is much simpler than it is for a table - the only tags allowed are <row> and <cell> tags. So it's pretty simple to generate those tags in a rule like this: var chart = '<row type=header><cell>foo<cell>bar<cell>abc'; chart += '<row><cell>' + Field("foo"); chart += '<cell>' + Field("bar"); chart += '<cell>' + Field("abc"); return chart; Quote Link to comment Share on other sites More sharing options...
DSweet Posted March 29, 2011 Share Posted March 29, 2011 Thanks, that helps. However, I have another question and a comment in regards to charting. My question is how do I put a border on a pie chart? If one of the colors that you are requested to use is white...then that slice of the pie actually looks like it is missing. There is no border around the individual slices nor the whole circle of the pie itself. I've even checked to see that the property "Draw Chart Border" is checked, but nothing shows for either a regular or an exploded pie chart. How do I get a border? My comment is in regards to adding "custom" colors to the chart. I would like to be able to name these colors instead of just having a bunch of colors named "custom". Thanks. . Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 29, 2011 Author Share Posted March 29, 2011 Please start a new thread with your chart-specific questions, so that we can keep this thread about the table API. Thanks. Quote Link to comment Share on other sites More sharing options...
esmith Posted June 22, 2011 Share Posted June 22, 2011 New question regarding tables: is there a way to center a table when it is included in a left-justified text frame? If I have body copy for a letter where I want to insert a 3-column table, but I want the table centered left to right, it appears that selecting the table rule in the text frame and clicking the center button does not work. Is there a property for alignment? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted June 22, 2011 Author Share Posted June 22, 2011 New question regarding tables: is there a way to center a table when it is included in a left-justified text frame? If I have body copy for a letter where I want to insert a 3-column table, but I want the table centered left to right, it appears that selecting the table rule in the text frame and clicking the center button does not work. Is there a property for alignment? Yes, you can use the alignment attribute of the <table> tag to control the alignment of the table itself within the text frame, as documented in the FusionPro Tags Reference Guide. Specifically, <table alignment=center>. Unfortunately, though, there's no property in the JavaScript Table API which corresponds to this. However, it's pretty easy to modify the tagging returned from the FPTable.MakeTags function, like so: var TableTags = myFPTableObject.MakeTags().replace(/^\<table/, "<table alignment=center"); Quote Link to comment Share on other sites More sharing options...
NPN Posted October 26, 2011 Share Posted October 26, 2011 Can this be used to solve the problem in this thread? http://forums.pti.com/showthread.php?t=454&highlight=border+graphic Meaning, can you make a dynamic table cell that fits to an uploaded graphic then make a border around it? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 26, 2011 Author Share Posted October 26, 2011 Can this be used to solve the problem in this thread? http://forums.pti.com/showthread.php?t=454&highlight=border+graphic Meaning, can you make a dynamic table cell that fits to an uploaded graphic then make a border around it? Yes. I'll answer in that other thread to keep this one on a narrower topic. Quote Link to comment Share on other sites More sharing options...
Doug Pershing Posted November 7, 2011 Share Posted November 7, 2011 I don't see a way to span rows or columns. Am I missing something? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 7, 2011 Author Share Posted November 7, 2011 I don't see a way to span rows or columns. Am I missing something? This is called "straddle" in FusionPro. From the original post: To combine or merge cells together, HStraddle and VStraddle can be used to straddle cells both Horizontally and Vertically:myTable.Rows[3].Cells[0].HStraddle = 2; myTable.Rows[3].Cells[2].VStraddle = 2; These properties correspond to the HStraddle and VStraddle attributes of the <cell> tag, as documented in the Tags Reference Guide. Quote Link to comment Share on other sites More sharing options...
Doug Pershing Posted November 7, 2011 Share Posted November 7, 2011 Thanks Dan. I found it just before you replied. Quote Link to comment Share on other sites More sharing options...
Doug Pershing Posted November 20, 2011 Share Posted November 20, 2011 Using the VStraddle causes the cell contents to duplicate down a cell. Quote Link to comment Share on other sites More sharing options...
DSweet Posted November 28, 2011 Share Posted November 28, 2011 Going back to your original post...your command to set the borders of the table includes the "thickness", "color" and "locations". MUST all these be equal? If I wanted to have a top and bottom border different from the left and right border how would I code this? I tried something like text.Rows[0].Cells[0].SetBorders.Top("Thin", "Red"); text.Rows[0].Cells[0].SetBorders.Bottom("Thin", "Green"); text.Rows[0].Cells[0].SetBorders.Right("Medium", "Blue"); text.Rows[0].Cells[0].SetBorders.Left("Medium", "Black"); but that caused an error stating thattext.Rows[0].Cells[0].SetBorders.Top is not a function I would like to know how to set each one in a tag. Thanks. . Quote Link to comment Share on other sites More sharing options...
Doug Pershing Posted November 28, 2011 Share Posted November 28, 2011 Top is not a function it is a parameter. Try this: text.Rows[0].Cells[0].SetBorders("Thin", "Red", "Top"); text.Rows[0].Cells[0].SetBorders("Thin", "Green", "Bottom"); text.Rows[0].Cells[0].SetBorders("Medium", "Blue", "Right"); text.Rows[0].Cells[0].SetBorders("Medium", "Black", "Left"); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 28, 2011 Author Share Posted November 28, 2011 Top is not a function it is a parameter. Try this: text.Rows[0].Cells[0].SetBorders("Thin", "Red", "Top"); text.Rows[0].Cells[0].SetBorders("Thin", "Green", "Bottom"); text.Rows[0].Cells[0].SetBorders("Medium", "Blue", "Right"); text.Rows[0].Cells[0].SetBorders("Medium", "Black", "Left"); Yes, that's correct. You could also do this: text.Rows[0].Cells[0].Rulings.Top.Color = "Red"; text.Rows[0].Cells[0].Rulings.Top.Thickness = "Thin"; text.Rows[0].Cells[0].Rulings.Bottom.Color = "Green"; text.Rows[0].Cells[0].Rulings.Bottom.Thickness = "Thin"; text.Rows[0].Cells[0].Rulings.Right.Color = "Blue"; text.Rows[0].Cells[0].Rulings.Right.Thickness = "Medium"; text.Rows[0].Cells[0].Rulings.Left.Color = "Black"; text.Rows[0].Cells[0].Rulings.Left.Thickness = "Medium";By the way, this entire table API is defined in the Builtins.js file, so feel free to look at the code and see how it generates the table tags. Please do not edit the Builtins.js file, however. Please feel free to suggest improvements to the API as well, since it's still open for enhancements. For instance, in the latest 7.2P1k release, there's a new FPTable.NewRow() function which returns the newly-added FPTableRow object, so that you don't have to remember the row index. Quote Link to comment Share on other sites More sharing options...
Doug Pershing Posted November 28, 2011 Share Posted November 28, 2011 Thanks Dan that helps. I have had trouble with the VStraddle command. Whenever I use it the contents of the cell always duplicates into the straddled cell below it. HStraddle works fine. Do you have any idea why the VStraddle would duplicate the contents? I removed all CopyCells commands to make sure it wasn't something I was doing. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 29, 2011 Author Share Posted November 29, 2011 Thanks Dan that helps. I have had trouble with the VStraddle command. Whenever I use it the contents of the cell always duplicates into the straddled cell below it. HStraddle works fine. Do you have any idea why the VStraddle would duplicate the contents? I removed all CopyCells commands to make sure it wasn't something I was doing. Please create a new thread with your specific question. If you can post an example, that would be great. Quote Link to comment Share on other sites More sharing options...
AndyShaw Posted April 4, 2012 Share Posted April 4, 2012 How would I use the API to set table attributes for the whole table, rather than cell by cell? Having to specify everything for every cell is rather tedious. Specifically, I want to set the margins and rules for the entire table, if that is possible, rather than doing it all cell by cell. Thanks, Andy P.S. I am using FusionPro 7.2P1k but am about to move up to FP 8.0. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 4, 2012 Author Share Posted April 4, 2012 How would I use the API to set table attributes for the whole table, rather than cell by cell? Having to specify everything for every cell is rather tedious. Specifically, I want to set the margins and rules for the entire table, if that is possible, rather than doing it all cell by cell. You can iterate through the cells and set whatever attributes you want, as in this example. Also take a look at the Money Table rule in the Frodo Travel tutorial. Quote Link to comment Share on other sites More sharing options...
AndyShaw Posted April 4, 2012 Share Posted April 4, 2012 Thanks, Dan, that will point me in the right direction. Javascript is not my strong suit. Andy Quote Link to comment Share on other sites More sharing options...
-Lisa- Posted January 2, 2013 Share Posted January 2, 2013 Dan, Happy New Year. I stumbled upon this posting while researching dynamic tables. This is great, thank you! However when I try building my rule, I receive the following error: "\Library\Application Support/Printable/FusionPro/Builtins.js, line 3252: TypeError: this.Cells[arguments] has no properties" Based on your original post, this should work in Version 7 and I'm running 7.2P1k on Mac OS X so I can't seem to figure out what's causing this? Quote Link to comment Share on other sites More sharing options...
step Posted January 2, 2013 Share Posted January 2, 2013 (edited) Lisa, my first thought is that you haven't specified what row the cell you're wanting to apply the arguments to. That being said, would you mind posting the block of code where you're building your table so that we could get a better idea? Edited January 3, 2013 by step Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.