Show Calculated Columns in a Grid

SAIL Recipes give you an opportunity to explore different interface design patterns. To learn how to directly use SAIL recipes within your interfaces, see Adapt a SAIL Recipe to Work with My Applications.


Display and sort on column whose data is not a field in the CDT but a calculated form of the data in the CDT.

This recipe uses an employee data structure and objects created through the Use the Write to Data Store Entity Smart Service Function on an Interface recipe. Make sure that recipes has been built first in order to see data in this recipe.

We will provide calculated vales in two column. First, we will concatenate firstName and lastName to display as a single display name. Secondly, we will look at an employee's start date, and determine that employee's next performance review date.


This scenario demonstrates:

  • How to concatenate to separate data points to create a single value
  • How to format a date so it's more readable
  • How to calculate a date conditionally


  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: 10,
    sort: a!sortInfo(
      field: "firstName",
      ascending: true
    * local!datasubset is pulling data from the employee data store entity 
    * from the entity backed record tutorial.
    * To use your data, change the constant from cons!EMPLOYEE_ENTITY to one of
    * your own. Then replace the fields in the queryColumns to a
    * relevant datapoint from your data store entity
    local!datasubset: a!queryEntity(
        selection: a!querySelection(columns: {
          a!queryColumn(field: "firstName"),
          a!queryColumn(field: "lastName"),
          a!queryColumn(field: "department"),
          a!queryColumn(field: "title"),
          a!queryColumn(field: "phoneNumber"),
          a!queryColumn(field: "startDate")
        pagingInfo: local!pagingInfo
      totalCount: local!datasubset.totalCount,
      columns: {
          label: "Name",
          field: "firstName",
          data: a!forEach(
            items: local!,
            expression: fv!item.firstName & " " & fv!item.lastName
          label: "Department",
          field: "department",
          data: index(local!, "department", null)
          label: "Title",
          field: "title",
          data: index(local!, "title", null)
          label: "Phone Number",
          data: index(local!, "phoneNumber", null)
          label: "Next Performance Review",
          field: "startDate",
          data: a!forEach(
            items: index(local!, "startDate", null),
            expression: text(
                    month(today()) > month(fv!item),
                    day(today()) > day(fv!item)
                  year(today()) + 1,
              "mmm dd, yyyy"
          alignment: "RIGHT"
      value: local!pagingInfo,
      saveInto: local!pagingInfo

Test it out

  1. Sort the grid by the "Name" column. Notice that the data sorts appropriately even across all pages of data.

Notable implementation details

  • In order to correctly sort on the calculated column, we queried the entire data set, calculated the new value for each row, then paged and sorted on the result. If you were to only calculate the column for the current page, sorting on the calculated column would not work correctly across pages.
  • Since you must query all data and then loop over each item to calculate the additional data, this technique should not be used for a large amount of data, as the query and calculation may become slow. To further optimize this grid, only perform the calculation on every row when the user sorts by the calculated column, otherwise, simply calculate the data for the current page.