Working With Forms > The Form Objects > Table

Table
The Table () form object represents a table with rows and columns. Enter the name of the Table object in the Name field. The table columns include headers.
Clear the Show headers check box to remove the headers.
Select the Automatically add new rows check box to make the table add a new row when the user enters new values in the same way as for tables containing global parameters and variables in the COMSOL Desktop.
Select the Sortable check box to make the table rows sortable. If you make table rows sortable, users can sort the rows by clicking the table column headers. The sorting is done in the following sequence: ascending, descending, and then unsorted (the original row order in the table).
In addition, the Settings window contains the following sections:
Sources
In this section you add the sources for the table data. The section contains a tree with a filtered view of the tree in the Application Builder window. The nodes either represent some sort of data or have children that do. For a table, arrays that you have added under Declarations are available as the data source for a table. When you select a node that represents data, the Add to Table toolbar button () below the tree becomes enabled. You can also right-click the node and choose Add to Table. The selected data source is then the source of the data displayed in the table. You can also click the Create button () in the Source section header to create a new variable declaration for the source and use it as the source. A Create and Use Variable dialog box opens, so that you can select the data type of the source (if applicable), its name, and its initial value. The name cannot be in conflict with any existing variable declaration. Click the Edit Node toolbar button () below the tree to move to the corresponding node.
In the table below, there is a row for each column where you can edit the header text under Header, the width (in pixels) under Width, and whether the table data is editable (the default) or not under Editable. The table columns where you select the Grow check box can grow horizontally. To make it possible to make table columns grow, the form in which you add the table must use the Grid mode, and you must also select Fill from the Horizontal alignment list under Position and Size (see below). You can adjust the alignment of the column’s data presentation using the lists in the Alignment column. Choose Left (the default), Center, or Right. The rightmost column, Data source, lists the sources for the data in each column.
Click the Move Up and Move Down buttons ( and ) to move and rearrange the column order. Click the Delete button () to delete the selected column.
Working with Data Sources
When you work with data sources for tables, the following rules apply, for example, when changing sources to a table from methods, but also if you perform a set command on a specific data source that is part of a table. In the rules below, the first data source of a table is the source that controls the number of rows in the table. All other sources used by the table will be padded with default element values or cropped to match the length of the first data source. The first data source has a lock symbol on its tree node.
Toolbar
In this section, you can add items to a table toolbar and activate the following table options:
From the Position list, choose where you want to position the toolbar relative to the table: Below (the default), Above, Left, or Right.
In the table below, you can add one or more buttons to form a table toolbar:
Click the Add Toolbar Commands button () to open the Toolbar Buttons dialog box, where you can select and add one or more of the following table commands as toolbar buttons:
Under Move ():
-
Double-click the Move Up () and Move Down () buttons to add corresponding buttons for moving rows.
Under Modify ():
-
Double-click the Add button () to add a button for adding rows.
-
Double-click the Delete button () to add a button for deleting selected rows.
-
Double-click the Clear Table button () to add a button for clearing the entire table of all its contents.
Under File ():
-
Double-click the Load from File (), Clear Table and Load from File (), and Save to File () buttons to add corresponding buttons for loading table data from a file, clearing the table first and then loading new content from a file, and saving table data to a file, respectively. The file types that users can load and save table data to and from include text files (.txt), CSV files (.csv), data files (.dat), and, if the license includes LiveLink™ for Excel®, Microsoft Excel® files (,xlsx). Allowed data separators are comma, semicolon, and tab for CSV files, and space and tab for other non-Excel® files.
Double-click the Move, Modify, and File buttons to add all buttons in those groups.
Alternatively, click the Add and Remove buttons to add and remove the selected buttons, respectively.
Click the Custom Button button to open the Edit Custom Toolbar Button dialog box (see The Edit Custom Toolbar Button Dialog Box).
Click OK to close the Toolbar Buttons dialog box and add the selected commands as buttons in the table’s toolbar. If you open the Toolbar Buttons dialog box again, it’s left side contains only the table commands that you have not added yet.
Click the Add Separator button () to add a separator between groups of buttons in the toolbar.
Select a button in the table and click the Edit button () if you want to change the appearance or behavior of a custom toolbar button in the Edit Custom Toolbar Button dialog box. Click the Move Up and Move Down buttons ( and ) to move and rearrange the toolbar button order. Click the Delete button () to delete the selected button.
Position and Size
This section contains all layout settings for a table in the grid of the parent form.
In the grid mode, you can control the horizontal and vertical alignment of the table using the following lists:
From the Horizontal alignment list, choose Left, Center, Right, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
From the Vertical alignment list, choose Middle, Top, Bottom, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
The need to specify the alignment is most obvious when working in the grid mode, as it controls how the form object is aligned in its grid cell. Aligning the form object can be useful in the sketch mode too, and you can then use the alignment tools on the Arrange menu in the Form toolbar’s Sketch section. When running the application in any client other than the Windows client, the form objects may not be positioned exactly as seen in the form windows. This is because the form objects may have a different size in other clients, giving them a slightly different positioning. Specifying the alignment ensures that the form objects are aligned as you want them to be in all clients.
You can also specify the height of the table. Enter a height (in points) in the Height field. If you have chosen Fill from the Horizontal alignment list, you can instead specify a Minimum width. Choose Automatic to compute the minimum width automatically (typically this means a minimum size of 0), or choose Manual to specify a minimum width in the text field underneath. The Width field is unavailable because the width of the table is determined by the software.
Additionally, in the sketch mode, you can specify the form object’s absolute position using the Position x and Position y fields. In the grid mode, you can position the object in the grid and see the grid position as the Row, Column, Row span, and Column span values.
Cell Margin
Under Cell margin (in grid mode only), you can control the margins around the form object. By default, the margins are taken from the parent form. From the Cell margin list, choose:
None, to use no margin around the form object.
From parent form (the default), to use the margins set for the parent form.
Custom, to specify the margins for the form object in the Horizontal and Vertical text fields.
Appearance
In this section, you can control the appearance of the text in the table.
From the Text color list, select a color to use for the text: Inherit (the default; the form object then uses the setting from the Form it is located in), any of the predefined basic colors, or Custom, which makes it possible to select a custom color from a color palette that opens.
The font and the font size for the text in the table use the font settings from the Forms node by default. Select a font from the Font list: Default font or any of the available fonts. If needed, choose or enter a font size (in points) in the Font size combo box. The default font size is Default size.
Select the Bold check box to use a boldface font.
Select the Italic check box to use italics (an italic font).
Under State, you can control the initial state of the table when users run the application. By default, the table is visible and enabled. Clear the Visible or Enabled check box if you want to make the initial state so that the table is hidden or unavailable. You can then make it visible or enable it using a method.
Events
For certain types of form objects, you can specify a method to run when an event such as data entry occurs. The On data change list contains None (the default) and any available methods. To add a local method for an event, click the Create Local Method button () to the right of the On data change list, or right-click the input field object. The selected method in the On data change list then changes to Local method and opens the editor window for the new method. To open the local method in a method editor window, click the Go to Source button (). An empty onDataChange editor window then opens, where you can define the local method. Click the Remove Local Method button () to delete the local method.
For events triggered by data change, the event is triggered after the new data value is stored in the data source.
You can also Ctrl+Alt-click on the table object:
If the On data change list is set to a method, Ctrl+Alt-click opens that method’s editor window.
If the On data change list is set to None, Ctrl+Alt-click creates a local method if needed, sets the list to Local method, and opens the local method’s editor window.