Good Morning Akram.
Perhaps the information, will give you a good start to implement this kind of functionality.
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 (see page 290) or static table (see page 288).
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:
- The key is the _id attribute of the column.
- The value is the value for the column.
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:
- You are using a report data object to populate the table based on user input.
- The user changes a selection in a select box (see page 287), meaning that the data must be refreshed.
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:
- The value of the _id attribute of the table is t.
- The values of the _id attributes of the columns are label and sf.
ca_fdSetTableRow(this.formId, ‘t’, 0, {‘label’ : ‘new row label’, ‘sf’ : ‘3’})
ca_fdFetchTableData(this.formId, ‘t’)
ca_fdGetTableRowCount(this.formId, ‘t’)
alert(JSON.stringify(ca_fdGetSelectedTableRows(this.formId, ‘t’)))
ca_fdUnselectTableRowsByIndex(this.formId, ‘t’, [0 ])
ca_fdUnselectTableRows(this.formId, ‘t’, [{ label text", sf)
ca_fdSelectTableRowsByIndex(this.formId, ‘t’, [0,1])
Thanks and kind regards, Louis.