9 Replies Latest reply: Nov 19, 2010 8:15 AM by HarryOhm RSS

    Possible to show/hide sections in a table?

    HarryOhm Community Member

      Hello all,


      First post here. I've only started using LiveCycle Designer a few weeks ago, never knowing that it came with my Acrobat. I've been busy converting forms we use in our business into pdf versions that can be filled, and created some with simple scripting etc.  Anyway my most ambitious effort to date is to create a gross payroll calculator in which I would enter the total hours worked for each employee and the gross payroll is calculated. The calculations I have no issue with.


      I am using a hidden "config" subform (thanks to kingphysh for your easy and simple example!) to store the employee names and payrates and the department they work in.


      My main form, the one on which I am entering total time for each employee, consists of a table with a section for each department. Thus I can put all employees in a department in one section of the table and then easily do subtotals by department etc.




            Dept. Name | Emp. Name | Pay Rate | Total Hrs | Gross Pay|  <-- this would be one row in the section     


            Dept. Name | Emp. Name | Pay Rate | Total Hrs | Gross Pay|

            Dept. Name | Emp. Name | Pay Rate | Total Hrs | Gross Pay|

      and so on. Each section also has a footer row for subtotals.


      This form will be used at various physical locations and not every location will have all departments. Thus I want the table to show only those sections for which the corresponding departments exist based on a selection (checkbox) that is on the hidden config page.


      Its not so much the actual scripting thats a problem, but where to put the script. Should I use a Table1 event or the checkbox event? I've tried both but neither works as desired. Or should I use an event for the individual rows in the section itself?


      Any pointers and suggestions will be greatly appreciated!




        • 1. Re: Possible to show/hide sections in a table?
          Niall O'Donovan Community Member

          Hi Harry,


          You could have a dropdown for all of the physical locations. Then in the exit event you could have a switch statement that would change the presence property of each table:


          switch (this.rawValue)
               case "Clonmel":
               Table1.presence = "hidden"; 
               Table2.presence = "visible";
               Table3.presence = "hidden";
               case "Cork":
               Table1.presence = "visible"; 
               Table2.presence = "visible";
               Table3.presence = "hidden";


          Hidden will exclude the table from the layout, so that if the page is set to flowed, then the other tables will move up to take up the space.


          Hope that helps,



          • 2. Re: Possible to show/hide sections in a table?
            HarryOhm Community Member



            Thanks for your quick reply. Appreciate the suggestion too!


            Unfortunately, with your suggestion I would have to know which locations have which departments. I would rather each location's manager set the departments. We're in the hotel business, so we have a limited number of departments (sales, desk, housekeeping, maintenance, etc.). Some locations might not have a "drivers" department if they don't have any shuttle buses, or some locations might have a "security" department, while smaller hotels in our portfolio would probably not.


            Thus if I put in all possible departments, and then enable each location to pick and choose which ones apply to them, it would be somewhat simpler. Also as new hotels are added into our company, we could use the form with out having to "re-do" the form, so to speak.


            Your suggestion to have separate tables for each department leaves open the question I had asked in my original post.


            I can get the section to "hide" but only by setting the presence value of each row and the footer in that section to "hidden". Setting the presence value of the entire section to hidden does not work.


            What i would like to do is if a checkbox is "checked" or "on", the section should be visible. If not, then the section remains hidden.


            What is the best way to achieve this?





            • 3. Re: Possible to show/hide sections in a table?
              Niall O'Donovan Community Member

              Hi Harry,


              Yes, using a series of checkboxes (one for each table) will work.


              Here is a sample: https://acrobat.com/#d=MnqBQrsWVc5gKwQFC9TyZA


              It uses radio buttons to change the presence. The same principle applies for checkboxes (by default selected = 1, not selected = 0)


              Therefore you can test the value of the checkbox in the click event and using an if statement make the presence of the associated table visible/hidden.


              Hope that helps,



              • 4. Re: Possible to show/hide sections in a table?
                HarryOhm Community Member



                Thanks again! After a bit of tinkering it works great with one caveat, I hope you will be able to shed some light on this as well.


                I am using a hidden "config" subform to hold a table in which the employee data (name and pay rate) is held. This "config table" is dynamic and I use a button to add rows as needed. I've also placed a button in each row to remove just that row, as opposed to removing the last or first etc. Thus if I have a 10 employees each on one row in the table, and decide to remove the employee name in the 5th row, I can do that without affecting the other rows. This was the easy part, thanks to an example file I found here - expandabletable-remthisrow.pdf (I think Stephan Cameron posted it - Thanks!)


                I then set the "add" button to trigger adding a row in the corresponding section in the table on the main form. This works fine.


                However, I would need to be able to set each "remove row" button to trigger the removal of the corresponding row from the table on the main form as well. This I have not been able to figure out.


                For example, here is the code to add a row in the table that holds the data (in the hidden subform) for the salaried employees:



                // adds row to table for salaried employees in config table



                //adds row to the Salaried section in the table on the main form


                And here is the code to remove a specific row in the same table in the config table



                //removes the row


                form1.page1.wrapper.CalcForm.Table1.Salaried._SAL.removeInstance(what do I use here?);

                // not working so far


                For example if I am removing the 5th row in the config table, I would want the corresponding (5th) row in the corresponding section of the table on the main form to be removed. All other rows before or after the removed row should remain unchanged.


                Any suggestions?




                • 5. Re: Possible to show/hide sections in a table?
                  Niall O'Donovan Community Member

                  Hi Harry,


                  The parameter for the removeInstance is the instance number that you want to delete. This is based on a zero numbering system, so the first row is instance number '0'. In a table you would access the instance number of the row that the delete button is in by using




                  The exact script would depend on your naming convention.


                  If you explore this example you will see that the remove instance in one table fires the click event in a button in a second table. Example here:





                  // '_' is shorthand for instanceManager, eg '_Row1'
                  // this.parent.index tells instanceManager to remove
                  // the row that the button is in. 
                  var vCurrentRow = this.parent.index; 
                  xfa.resolveNode("page2.Table2.Row1[" + vCurrentRow + "]").deleteBtn.execEvent("click");



                  Note that the parameter for the addInstance is 1/true or 2/false, which relates to true=merging the new instance with the data model. 


                  Hope that helps,



                  • 6. Re: Possible to show/hide sections in a table?
                    HarryOhm Community Member



                    That is precisely what I am trying to accomplish.


                    You just made my evening! 



                    Many many thanks!!




                    • 7. Re: Possible to show/hide sections in a table?
                      HarryOhm Community Member

                      Sorry to keep revisiting this thread but after much wasted time I figure asking for help is the best thing to do.


                      My table has one header, six sections each with a variable number of body rows and a footer for subtotals, and after the sections, a footer for grand totals.


                      It looks like this:


                      HEADER FOR THE TABLE


                      Section1 -body row 1

                                     body row 2

                                     body row 3

                                     SECTION 1 FOOTER

                      Section2 -body row1

                                     body row2

                                     body row3

                                     body row4

                                     SECTION 2 Footer


                      FOOTER FOR WHOLE TABLE


                      I would like to be able to have sections appear only if necessary, and the trigger would be a checkbox in a hidden subform.


                      I can get individual body rows within the section and the section footer to hide, but I can't get the section as a whole to hide in one fell swoop.


                      In fact the only presence property I see for the sections is Visible, Visible (Screen Only), and Visible (Print Only). The rest are grayed out.  The screenshot below shows the issue.




                      Is this possible? I mean to hide sections (or groups of rows), rather than just single rows. If so what should I be looking for or doing?


                      Another question I have is this. Depending on the data, the sections could have more rows than could fit on a single page. What is the best way to deal with this, so that the table header appears at the top of each page, and the table footer only on the last page?  It would be preferable to do this in a way

                      so that if a section was going to end up spanning two pages, the whole section would instead go onto the next page rather than be split.






                      Message was edited by: HarryOhm I tried the "insert image" function for the screenshot but for whatever reason it does not work.  

                      • 8. Re: Possible to show/hide sections in a table?
                        Niall O'Donovan Community Member

                        Hi Harry,


                        With repeating elements you can un-tick the minimum count (Object > Binding palette), so that when the form is rendered there will not be an instance on the form.


                        However because in your case the body row is the repeating element and not the section, while you can initially hide the body row, I don't think you will have much joy hiding the footer.


                        As far as I can tell, you cannot script for the presence of the table section (visible/hidden), so having a checkbox to hide the section will probably not help.


                        The only work around I can think of is to un-tick the min count of the body row and have the checkbox show/hide the footer row of the section.


                        Example here: https://acrobat.com/#d=4Nj*BeqL1iG-6tfQBLoIfA


                        If you wanted to hide the body rows as well, then you would need to loop through, see the script in the click event of the checkboxes.


                        In relation to the headers, if you select the header row, in the Object > Pagination palette you can specify that the header row appears on subsequent pages. (this sometimes doesn't work when the table goes over many pages).


                        While you can disallow content page breaks within content for most objects, I don't think that you can specify it for sections.


                        Hope that helps,



                        • 9. Re: Possible to show/hide sections in a table?
                          HarryOhm Community Member



                          Many thanks for all your help. With the examples you provided, I have been able to almost finish the form and learned a little bit along the way too.


                          There are a couple of things still vexing me though.


                          My form's hierarchy is as follows:


                          page1 (flowed)

                               - wrapper (flowed)

                                    - form1  (positioned)  <-- sub-form (form on which data is entered and calculation results are displayed_

                                         - table1


                                              -Section1 - bodyrow

                                                             - section1 footer

                                              -Section2 - bodyrow

                                                              - section2 footer



                                    - config   (positioned) <--  sub-form (normally hidden "config" form which stores employee data - accessed by password

                                         - table1


                          The sub-form form1 contains a table with six sections. Each section represents one department and has  body rows and a footer row for subtotals.

                          the number of body rows in each section can vary with the number of employees in the department.


                          I have two issues remaining with the form and it will be done. Hopefully you will be able to point me in the right direction.


                          1. Pagination - in the form, I have set page1 to "flowed". wrapper is also flowed. form1 is positioned.


                               I would like to be able to set it so that if any section is going to be split, it would go onto the next page.

                               The header should be repeated in each page. Each section footer should be with the section, and the Table footer should be on the last page.


                          2. Column Subtotals


                               I have set the form to be as general purpose as possible. Thus it can take time totals in either decimal or HH:MM format. I am having trouble adding columns of time totals in HH:MM format.


                          For example, given 3 time totals (all are in text fields):






                          I would thing the best way to do this is to parse the strings and add the minutes and hrs separately and then depending on the total of the minutes, use the floor and mod functions to get the correct total. I just can't get it to add the columns at all.


                          This is the code I am using to add the column:


                          if (_FD.count gt 0) then   //make sure at least one body row exists in this section


                          for i = 1 upto (_FD.count) do

                          mins = Sum(Right (FD[i].fdr_tot[i], 2))        // FD is the row and fdr_tot is the cell in the row which is to be included in the calc.

                          hrs = Sum(Left (FD[i].fdr_tot[i], (Len (FD[i].fdr_tot[i]) - 3)))






                          I've tried using the code below as well to no avail.
                          mins = Sum(Right (FD[*].fdr_tot[*], 2))
                          hrs = Sum(Left (FD[*].fdr_tot[*], (Len (FD[*].fdr_tot[*]) - 3)))


                          Any suggestions will be greatly appreciated.