Compute summary Values

Description

Computing summary values on the server-side. For List controls that are based on SQL data, you can specify that summary data (e.g. total, avg, count, min and max - total and avg are only available for numeric fields) should be computed for certain columns in the List control.

Client-side summary values can also be computed. Client-side summaries are not limited to SQL data sources.

The summary computations are based on the List query (not on the rows actually visible in the List). In the case of a paginated List, there may be more rows in the query than are visible in the List. For example, the query might have 1,000,000 rows, but the list might show 20 rows at a time. If the List is not paginated, then the number of rows in the List is the same as the number of rows in the List query.

Server-side summary values are automatically updated when the List data is refreshed. If your UX is data-bound and you have specified that the List should be updated when records are updated or saved, the server-side summaries will be updated when data in the List is edited.

To turn on summary calculations for a column in a List, check the 'Compute summary values' property. Once this property is checked, the 'Summary field formatting' property is shown where you can define display formats for the data. For example, to round the average to 2 decimal places, you would use:

round(,2)

You can use any Xbasic function for format the data.

images/sum2.png

When you compute summary data for a List column, you will typically want to display the data on the UX component. The List's afterServerSideSummaryCompute event is useful for this. The afterServerSideSummaryCompute fires after the server-side summary values have been updated. In this event handler you can reference the summary data that was computed. Here are some examples of how your Javascript code can reference summary values:

summary['QTY'].total
summary['PRICE'].avg
summary['PRICE'].max

The 'summary' object contains all of the summary data. The field name must be in uppercase and the summary type (total, avg, count, min, or max) must be in lower case. You can also use a method of the UX object to read a List summary value using the following method:

{dialog.object}.getListServerSideSummaryValue(listName, fieldName, summaryType)

For example:

var tot = {dialog.object}.getListServerSideSummaryValue('list1','QTY','total');