Tables are a little more complex than other PerfectApps objects because a Table object itself can contain other app objects. For most table calculations, you work in the same way as you would for ordinary app fields. However, sometimes you need to operate across all rows of the table, for example when summing rows to a total field.
Current Row and All Rows
When you are getting data from or writing results to fields that involve table fields, you will be presented with a dialog like the one below. You will notice that for each table column, there are two options - Current Row and All Rows.
•Current Row - Use this if you wish to write data to or read data from the specified field in the currently selected row of the table.
•All Rows - Use this where you want to write data to or read data from each row in the Table. There are certain special actions that will require you to write data using the All Rows option.
Example: Calculate the total of a table column whenever data in the table is changed: |
Use the Sum function to accomplish this. Let's assume you have a number field underneath a table column (numeric) of a table object.
1.With a app loaded in the App Designer, click the behavior event used to trigger the behavior. 2.Drag in a Set Field command and then in the Properties panel set the Field to be the number field. In the Value field, select Formula and then click Compose. 3.Click Add Function and select Sum in the Function list. 4.Click in the <empty> field within the Sum function and then locate the table object. Within that object, all table columns are listed. For each column there are two entries: Current Row and All Rows. Select All Rows to sum all rows in the table. When completed, it will look like this: |
See also: Working with List Values
Return to: Using the Formula and Condition Editor, Designing an App