Virtual Javascript Column
Description
A List field whose value is computed using JavaScript.
Discussion
The Virtual Javascript column is a field whose value is computed by executing JavaScript code when the List is rendered. Virtual Javascript columns automatically update while a List is edited. They can also be sorted.
To add a Virtual Javascript field to a List click the Add Item button on the List Builder Fields tab. Then, select Virtual Javascript.
Next, define the Javascript code that must be executed to return the value for the Virtual Javascript field.
The JavaScript that computes the value for the field can reference several variables:
- Variable
- Description
- data
An object with data for all fields in the row. For example, data.FirstName
Note that field names are case sensitive and must match exactly as they are shown in the field listing.
- data['*key']
The zero based row number of the current row in the List for which the Virtual Javascript field is being rendered.
- lObj
A pointer to the List object.
For example, the JavaScript below computes the total for a row by multiplying the Quantity and UnitPrice fields together. The result is formatted as a currency value and returned from the script:
var total = Number(data.Quantity) * Number(data.UnitPrice); var result = total.toFormat("$#,##0.00"); return result;
Virtual Javascript vs Computed Columns
A Virtual Javascript field is very similar to defining a computed column using the Computed columns property in the List Builder. The primary difference is that when a List row is in edit mode (using in-place editing) the values in Virtual Javascript fields are updated as the List is being edited, whereas the values in computed columns are only update when the List row is saved.
See Also