Jim B. Posted May 28, 2014 Share Posted May 28, 2014 (edited) Hello, I am looking for help with suppressing rows in a table. What i need is, if the "Content1" and "Content2" fields are not filled out, then the rest of the rows move up and if the same fields are filled out then the copy prints. Right now if the "Content1" and "Content2" fields are not filled out, there is a gap showing. I believe i need a rule, just not sure on how to create one. Attached is my table. var myTable = new FPTable; myTable.AddColumns(7100, 26000); myTable.AddRows(24); myTable.Rows[0].Cells[0].Font="Myriad Pro Light"; myTable.Rows[0].Cells[0].TextColor="Black"; myTable.Rows[0].Cells[0].Margins = new FPTableMargins; myTable.Rows[0].Cells[0].Margins.Right = 0; myTable.Rows[0].Cells[0].Content = Field("Time1"); myTable.Rows[0].Cells[1].Font="Myriad Pro Light"; myTable.Rows[0].Cells[1].TextColor="Black"; myTable.Rows[0].Cells[1].Margins = new FPTableMargins; myTable.Rows[0].Cells[1].Margins.Right = 0; myTable.Rows[0].Cells[1].Content = Field("Title1"); myTable.Rows[1].Cells[1].Font="Myriad Pro Light"; myTable.Rows[1].Cells[1].TextColor="Black"; myTable.Rows[1].Cells[1].Margins = new FPTableMargins; myTable.Rows[1].Cells[1].Margins.Right = 0; myTable.Rows[1].Cells[1].Margins.Top = -20; myTable.Rows[1].SetContents( "", Field("Content1")); myTable.Rows[2].Cells[0].Font="Myriad Pro Light"; myTable.Rows[2].Cells[0].TextColor="Black"; myTable.Rows[2].Cells[0].Margins = new FPTableMargins; myTable.Rows[2].Cells[0].Margins.Right = 0; myTable.Rows[2].Cells[0].Margins.Top = -10; myTable.Rows[2].Cells[0].Content = Field("Time2"); myTable.Rows[2].Cells[1].Font="Myriad Pro Light"; myTable.Rows[2].Cells[1].TextColor="Black"; myTable.Rows[2].Cells[1].Margins = new FPTableMargins; myTable.Rows[2].Cells[1].Margins.Right = 0; myTable.Rows[2].Cells[1].Margins.Top = -10; myTable.Rows[2].Cells[1].Content = Field("Title2"); myTable.Rows[3].Cells[1].Font="Myriad Pro Light"; myTable.Rows[3].Cells[1].TextColor="Black"; myTable.Rows[3].Cells[1].Margins = new FPTableMargins; myTable.Rows[3].Cells[1].Margins.Right = 0; myTable.Rows[3].Cells[1].Margins.Top = -20; myTable.Rows[3].SetContents( "", Field("Content2")); myTable.Rows[4].Cells[0].Font="Myriad Pro Light"; myTable.Rows[4].Cells[0].TextColor="Black"; myTable.Rows[4].Cells[0].Margins = new FPTableMargins; myTable.Rows[4].Cells[0].Margins.Right = 0; myTable.Rows[4].Cells[0].Margins.Top = -5; myTable.Rows[4].Cells[0].Content = Field("Time3"); myTable.Rows[4].Cells[1].Font="Myriad Pro"; myTable.Rows[4].Cells[1].TextColor="Black"; myTable.Rows[4].Cells[1].Margins = new FPTableMargins; myTable.Rows[4].Cells[1].Margins.Right = 0; myTable.Rows[4].Cells[1].Margins.Top = -5; myTable.Rows[4].Cells[1].Content = Field("Title3"); myTable.Rows[5].Cells[1].Font="Myriad Pro Light"; myTable.Rows[5].Cells[1].TextColor="Black"; myTable.Rows[5].Cells[1].Margins = new FPTableMargins; myTable.Rows[5].Cells[1].Margins.Right = 0; myTable.Rows[5].Cells[1].Margins.Top = -20; myTable.Rows[5].SetContents( "", Field("Content3")); myTable.Rows[6].Cells[0].Font="Myriad Pro Light"; myTable.Rows[6].Cells[0].TextColor="Black"; myTable.Rows[6].Cells[0].Margins = new FPTableMargins; myTable.Rows[6].Cells[0].Margins.Right = 0; myTable.Rows[6].Cells[0].Margins.Top = -5; myTable.Rows[6].Cells[0].Content = Field("Time4"); myTable.Rows[6].Cells[1].Font="Myriad Pro"; myTable.Rows[6].Cells[1].TextColor="Black"; myTable.Rows[6].Cells[1].Margins = new FPTableMargins; myTable.Rows[6].Cells[1].Margins.Right = 0; myTable.Rows[6].Cells[1].Margins.Top = -5; myTable.Rows[6].Cells[1].Content = Field("Title4"); myTable.Rows[7].Cells[1].Font="Myriad Pro Light"; myTable.Rows[7].Cells[1].TextColor="Black"; myTable.Rows[7].Cells[1].Margins = new FPTableMargins; myTable.Rows[7].Cells[1].Margins.Right = 0; myTable.Rows[7].Cells[1].Margins.Top = -20; myTable.Rows[7].SetContents( "", Field("Content4")); myTable.Rows[8].Cells[0].Font="Myriad Pro Light"; myTable.Rows[8].Cells[0].TextColor="Black"; myTable.Rows[8].Cells[0].Margins = new FPTableMargins; myTable.Rows[8].Cells[0].Margins.Right = 0; myTable.Rows[8].Cells[0].Margins.Top = -5; myTable.Rows[8].Cells[0].Content = Field("Time5"); myTable.Rows[8].Cells[1].Font="Myriad Pro Light"; myTable.Rows[8].Cells[1].TextColor="Black"; myTable.Rows[8].Cells[1].Margins = new FPTableMargins; myTable.Rows[8].Cells[1].Margins.Right = 0; myTable.Rows[8].Cells[1].Margins.Top = -5; myTable.Rows[8].Cells[1].Content = Field("Title5"); myTable.Rows[9].Cells[1].Font="Myriad Pro Light"; myTable.Rows[9].Cells[1].TextColor="Black"; myTable.Rows[9].Cells[1].Margins = new FPTableMargins; myTable.Rows[9].Cells[1].Margins.Right = 0; myTable.Rows[9].Cells[1].Margins.Top = -20; myTable.Rows[9].SetContents( "", Field("Content5")); return myTable.MakeTags(); Edited May 28, 2014 by Jim B. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 29, 2014 Share Posted May 29, 2014 All that copied-and-pasted code makes my head hurt. Use a for loop instead, like so: var myTable = new FPTable; myTable.AddColumns(7100, 26000); myTable.AddRows(24); for (var i = 1; i <= 5; i++) { var r = (i - 1) * 2; myTable.Rows[r].Cells[0].Font="Myriad Pro Light"; myTable.Rows[r].Cells[0].TextColor="Black"; myTable.Rows[r].Cells[0].Margins = new FPTableMargins; myTable.Rows[r].Cells[0].Margins.Right = 0; myTable.Rows[r].Cells[0].Content = Field("Time" + i); myTable.Rows[r].Cells[1].Font="Myriad Pro Light"; myTable.Rows[r].Cells[1].TextColor="Black"; myTable.Rows[r].Cells[1].Margins = new FPTableMargins; myTable.Rows[r].Cells[1].Margins.Right = 0; myTable.Rows[r].Cells[1].Content = Field("Title" + i); r++; myTable.Rows[r].Cells[1].Font="Myriad Pro Light"; myTable.Rows[r].Cells[1].TextColor="Black"; myTable.Rows[r].Cells[1].Margins = new FPTableMargins; myTable.Rows[r].Cells[1].Margins.Right = 0; myTable.Rows[r].Cells[1].Margins.Top = -20; myTable.Rows[r].SetContents( "", Field("Content" + i)); } return myTable.MakeTags(); Or, better yet: var myTable = new FPTable; myTable.AddColumns(7100, 26000); myTable.AddRows(24); for (var i = 1; i <= 5; i++) { var r = (i - 1) * 2; var cell = myTable.Rows[r].Cells[0]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Time" + i); cell = myTable.Rows[r].Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Title" + i); r++; cell = myTable.Rows[r].Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Margins.Top = -20; cell.Content = Field("Content" + i); } return myTable.MakeTags(); I still haven't answered your question, but with the code being more concise, it's easier to see what needs to be changed. First off, you don't need to add all the rows at the beginning; you can add them "on the fly" as you need them, like so: var myTable = new FPTable; myTable.AddColumns(7100, 26000); for (var i = 1; i <= 5; i++) { var row = myTable.AddRow(); var cell = row.Cells[0]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Time" + i); cell = row.Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Title" + i); row = myTable.AddRow(); cell = row.Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Margins.Top = -20; cell.Content = Field("Content" + i); } return myTable.MakeTags(); You can see that the math we had to do before to figure out the actual row number goes away. We just add a row object as we need it, and use it directly. Now, it's pretty easy to simply not add rows when there's no content for them, like so: var myTable = new FPTable; myTable.AddColumns(7100, 26000); for (var i = 1; i <= 5; i++) { if (!Field("Content" + i)) continue; // Don't add rows if Content is empty. var row = myTable.AddRow(); var cell = row.Cells[0]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Time" + i); cell = row.Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Title" + i); row = myTable.AddRow(); cell = row.Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Margins.Top = -20; cell.Content = Field("Content" + i); } return myTable.MakeTags(); Voila! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 29, 2014 Share Posted May 29, 2014 P.S. To anyone else out there who wants to try to answer questions like this, but doesn't have a data file with all the required fields handy, you can add something like this at the top of your rule to make something you can see in the output: function Field(name) { return "***" + name + "***"; } In this case, to validate that "empty" fields are skipped, I just modified it a bit: function Field(name) { if (Right(name, 1) == "1") return ""; return "***" + name + "***"; } Quote Link to comment Share on other sites More sharing options...
Jim B. Posted May 29, 2014 Author Share Posted May 29, 2014 Hi Dan, Thanks for taking the time to edit my code. I added the not adding rows when there's no content code. When no copy is added to the "Content" field the "Time" and "Title" fields disappear. I need the "Time" and "Title" fields to show even if there is copy or no copy in the "Content" field. When no copy is added to the "Content" field then the "Content" field suppresses and the remaining type moves up to fill the space. Attached is a screen shot of an example of my copy. Your help is appreciated. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 29, 2014 Share Posted May 29, 2014 HI need the "Time" and "Title" fields to show even if there is copy or no copy in the "Content" field. I see. I misunderstood your original post: What i need is, if the "Content1" and "Content2" fields are not filled out, then the rest of the rows move up and if the same fields are filled out then the copy prints. I read that as "If the Content field is empty, suppress the rest of the related rows." Anyway, it's easy to fix. Just move the test for empty content to after the other row has already been added: var myTable = new FPTable; myTable.AddColumns(7100, 26000); for (var i = 1; i <= 5; i++) { var row = myTable.AddRow(); var cell = row.Cells[0]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Time" + i); cell = row.Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Content = Field("Title" + i); if (!Field("Content" + i)) continue; // Don't add row if Content is empty. row = myTable.AddRow(); cell = row.Cells[1]; cell.Font="Myriad Pro Light"; cell.TextColor="Black"; cell.Margins = new FPTableMargins; cell.Margins.Right = 0; cell.Margins.Top = -20; cell.Content = Field("Content" + i); } return myTable.MakeTags(); 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.