ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Developing an application or website / Controls, windows and pages / Controls: Available types / Table control
  • Overview
  • How to?
  • Implementation
  • Position of calculation row
  • Customizing the calculation row
  • Deleting the custom calculation rows
  • Exporting the results of calculations
  • Export via the AAF (Automatic Application Features) of Table control
  • Export via the WLanguage functions
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
WINDEV allows you to easily insert automatic calculations into the columns found in the Table and TreeView Table controls.
From version 22, you also have the ability to perform automatic calculations in the columns found in the Table and TreeView Table controls. These calculations are performed through programming.
How to?

Implementation

To add a custom calculation in the column of a Table control (or TreeView Table), use TableFormulaAdd.
This function expects as parameter:
  • the name of the column taken into account for the calculation.
  • the caption of the row that displays the calculation in the Table control. If this caption does not exist, the row will be created. If this caption exists, the calculation will be displayed in the requested column.
  • the name of three procedures. These procedures are used to:
    • initialize the calculation,
    • to perform a calculation for each row of the Table control,
    • perform the final calculation if necessary.
Example:
TableFormulaDeleteAll(TABLE_MyTable)
nRow is int
nRow = TableFormulaAdd(TABLE_MyTable.COL_Num, "Positive mean", ProcInit, ProcAdd, ProcEnd)
// Change the background color of the row for custom calculation
COL_Num[nRow].BackgroundColor = LightRed
 
nCounter is int
INTERNAL PROCÉDURE ProcInit()
nCounter = 0
RESULT 0
END
 
INTERNAL PROCÉDURE ProcAdd(Accumulator, ColValue)
// Ignores the negative numbers or NULL
IF (ColValue <= 0) RESULT Accumulator
nCounter++
RESULT Accumulator + ColValue
END
INTERNAL PROCÉDURE ProcEnd(Accumulator)
IF nCounter = 0 THEN RESULT 0
// Calculate the mean
RESULT Accumulator/nCounter
END
Remarks:
  • The custom calculation rows are automatically recalculated as soon as the content of the Table or TreeView Table control changes.
    Tip: The iteration procedure is called for each row: we advise you not to perform slow calculations (avoid the accesses to the database for example).
  • The TotalsEnabled property does not allow or forces automatic or custom calculations in a Table control.
  • If the DisplayEnabled property is used on the Table control and is set to False, the column calculations are not updated.
  • The following syntax is used to retrieve the value of the custom calculation for a column:
    <Table control>.<Column name>[Row number]
    where <Row number> is the row index returned by TableFormulaAdd.

Position of calculation row

To configure the position of automatic or custom column calculations:
  1. Go to the "General" tab of the Table control (to do so, select the name of the Table control and click "General").
  2. Specify the location of totals. To display the results:
    • in one or more rows directly added after the last control row, check "In the table, after the last row".
      These rows are visible:
      • at the bottom of the Table control if the control includes no vertical scrollbar.
      • when the vertical scrollbar is located at the very bottom if the Table control includes a vertical scrollbar.
    • below the Table control, check "Below the table".
      These rows are always visible.
    • you also have the ability to perform column calculations without displaying them ("No display" option).
  3. Validate the Table control description window.

Customizing the calculation row

You have the ability to customize (caption, color, font, height, ...):
  • the added row by using the following syntax:
    <Table control>[Row number].<Property> = <New value>
  • the cell containing the result by using the following syntax:
    <Table control>.<Column name>[Row number].<Property> = <New value>

    Caution: the first column contains the caption of the calculation if it exists.
where:
  • <Row number> is the row index returned by TableFormulaAdd.
  • <Property> can correspond to one of the following properties:
    BackgroundColorUsed to find out and modify the background color of a calculation cell.
    CaptionUsed to find out and modify the caption of the row containing a calculation cell.
    ColorUsed to find out and modify the color of the text displayed in a calculation cell.
    FontAllows you to find out and modify the font used in a calculation cell.
    FontBoldUsed to find out and modify the "Bold" attribute for the column elements.
    FontCondensedUsed to find out whether the characters of column elements are condensed or not, and to condense (or not) the characters of column elements.
    FontExtendedUsed to find out whether the characters of column elements are extended or not, and to extend (or not) the characters of column elements.
    FontItalicUsed to find out and modify the "Italic" attribute for the column elements.
    FontLargeUsed to find out whether the characters of column elements are enlarged or not, and to enlarge (or not) the characters of column elements.
    FontNameUsed to find out and modify the font used for the column elements.
    FontSizeUsed to find out and modify the size of the font used for the column elements.
    FontStrikeOutUsed to find out and modify the "StrikeOut" attribute for a calculation cell.
    FontUnderlinedUsed to find out and modify the "Underline" attribute for the column elements.
    HeightUsed to find out and modify the height of a calculation cell.
    NameUsed to find out the name of a calculation cell.
    NoteUsed to find out and modify the notes associated with a calculation cell.
    StateGets and changes the display state of the row containing the calculation cell.
    VisibleUsed to find out whether a column is visible and to make a column visible/invisible.
    WidthUsed to find out and modify the width of a calculation cell.

Deleting the custom calculation rows

To delete the custom calculation rows, use TableFormulaDeleteAll.
Exporting the results of calculations

Export via the AAF (Automatic Application Features) of Table control

The context menu of Table and TreeView Table controls contains several options to export the control content.
During this export, the results of custom calculations are exported.
Remark: Only the value is exported, not the caption.

Export via the WLanguage functions

Several WLanguage functions can be used to export the content of a Table control in a specific format (Word, Excel, XML, ...). During this export, the rows corresponding to calculations are also exported by default.
To avoid exporting the calculation rows, all you have to do is specify the taNoTotal constant in the following functions:
TableToClipboardCopies the content of a Table or TreeView Table control to the clipboard.
TableToExcelCreates an Excel file with the data from a Table or TreeView Table control.
TableToTextCreates a character string from the data found in a Table or TreeView Table control.
TableToWordCreates a Word file (.RTF) from the data found in a Table or TreeView Table control.
TableToXMLCreates an XML file from the data found in a Table or TreeView Table control.
Minimum version required
  • Version 22
Comments
Click [Add] to post a comment

Last update: 01/26/2023

Send a report | Local help