Previous Topic: How to Use JavaScript Functions in Fields

Next Topic: How to Populate Fields Based on User Input to a Report Data Object

Predefined JavaScript Functions for Tables Only

The following predefined JavaScript functions apply to tables only:

ca_fdAddTableRow(formId, tableId, {}):

Adds a row to the table.

Object attributes correspond to the _id of the table columns. The values of the attributes correspond to the value of the cell in the row.

The third argument contains the row data as a JavaScript object, for example, {'userid':'spadmin','age':'31'}.

The following call adds a row with cells named spadmin and 31:

ca_fdAddTableRow('myForm','myTable',{'userid':'spadmin','age':'31'}) 

The newly added row is automatically selected. The table contains two columns whose _id values are userid and age.

ca_fdRemoveTableRow(formId, tableId, {}):

Removes the specified row from the table.

Note: This function removes only rows that users added while editing the form during a request. This function does not remove rows that an administrator populated while creating a dynamic table or static table.

The values of the object attributes correspond to the values of the _id attributes of the cell in the row.

The third argument contains the row data as a JavaScript object, for example, {'userid':'spadmin','age':'31'}. This argument is comma-separated list of key, value pairs, where:

Note: Keys and values do not need to be string constants, but can be JavaScript expressions that evaluate to strings.

For example, the following call removes a row with cells named spadmin and 31:

ca_fdRemoveTableRow('myForm','myTable',{'userid':'spadmin','age':'31'}) 
ca_fdRemoveAllTableRows(formId, tableId):

Removes all rows from the table, except the rows that were dynamically or statically populated, as explained in the note for the previous item, ca_fdRemoveTableRow(formId, tableId, {}).

The following call removes all user-added rows from the specified table:

ca_fdRemoveAllTableRows('myForm','myTable')
ca_fdFetchTableData(formId, tableId):

Reruns the report data object associated with the table and refreshes the data in the table.

This function is useful to refresh data based on a change in user input, for example, if both of the following are true:

Note: This function is valid only when you use a report object attribute to populate the table.

ca_fdGetTableRowCount(formId, tableId):

Returns the number of rows in the table.

ca_fdGetTableSelectedRowCount(formId, tableId):

Returns the number of selected rows in the table.

ca_fdGetSelectedTableRows(formId, tableId):

Returns all selected table rows as JavaScript objects.

Examples

The following are sample JavaScript functions for tables, for illustration. In these examples, the following apply: