The Robertson Team


  Programmers' Tools >  The Free Stuff >  GridMonger >  FAQ >  Whats the deal with calculated columns?

Whats the deal with calculated columns?

A calculated column can reference any ColdFusion data present on the current row. It can also reference any variables you specify via your own programming outside the grid, where that information is available to the current page request. Since the calculation you specify will be run verbatim through a ColdFusion Evaluate() statement, use standard ColdFusion operators. Your formula should look exactly like what it would inside of a ColdFusion Evaluate() statement... without Evaluate() surrounding it.

  • EXAMPLE: GetData.Latitude+1/2
  • EXAMPLE: GetData.City & " " & GetData.State
  • EXAMPLE: GetData.Latitude+1/2-client.foocount

To create a calculated column:

  1. Pick a field to display that is not displayed in another column of this grid (do not choose the primary key).
  2. Choose 'Calculated Column' from the drop-down list in the GridBuilder field editor (or designate the field with a 'C' in variables.DisplayType and/or variables.ExpandedDisplayType if performing the task manually).
  3. You can make the field editable or not as you like. If the field is editable you will be editing the field contents, NOT the calculation formula.
  4. Enter your other field/column parameters. Calculated columns can not be searched on or sorted. They are for display only. Set your field parameters accordingly to prevent searching and sorting on your calculated column.
  5. Enter your calculation formula. if you use double quotation marks in your statements you MUST escape them properly (i.e. double them up. Single quotes often work as a substitute).

Remember that if the calculated column is editable, the raw contents of this field will not be visible unless the grid is in edit mode and the field is marked as editable, at which point the calculation will not display and the field contents will be visible. If you are in edit mode and the field is marked as NOT editable, then the calculation will continue to display and the field contents will remain hidden.

The ability to edit the field being calculated, even though that field's contents cannot be seen outside of edit mode, can provide a significant level of flexibility. As an example, if your calculation is GetData.HourlyRate*1.15 You could assign the field that is the calculated column to be HourlyRate (remember, it can be *anything* so long as it is not displayed somewhere else and it is not the primary key). This would make your calculation self-referencing. This in turn allows you to alter your displayed calculated value by editing the field in the grid.

NOTE: The query that displays data in GM is named "GetData". If you specify a field from your grid in your formula this field must be specified either in normal and expanded view or in the HiddenField list.

NOTE: Do NOT use a tilde character ("~") anywhere in this statement! This character is reserved for GM's internal use!

The Robertson Team,
1.559.360.1717 is a leader in ColdFusion web hosting and managed dedicated servers.