The tabular views make heavy use of Angular directives, to keep the source code concise. However, it can be tricky to understand what all those non-standard-HTML attributes are for. This page sheds some light on the mystery. In addition, further configuration options / variants are described.
Notes on Directives
The refresh button is declared something like this:
The refresh class is defined in table.css to style the <div> element appropriately for light and dark themes, when active or hovered-over.
The ng-class directive is provided by Angular and adds the specified class to the element if the condition is true. In this case, if the autoRefresh boolean (defined on our controller scope) is true, then the active class is applied to the <div> element.
icon icon-id="refresh" icon-size="36"
The icon directive injects an icon with the given icon-id into the <div> element. icon-size="36" is the recommended size for table button icons.
If you really want to get into the guts of the code, see the definition of the icon directive in icon.js.
The tooltip directive uses the string stored on the scope variable autoRefreshTip to populate a tooltip when the mouse hovers over the button.
The ng-click directive, provided by Angular, invokes the toggleRefresh() function (defined on our scope) when the user clicks on the <div> element.
Notes on Main Table
The onos-table-resize directive monitors the browser window and resizes the table elements whenever the window size changes. See table.js for the gory details.
Note that the table view makes use of two HTML <table> elements; the first for the (non-scrolling) table headers, and the second for the (scrolling) table contents:
onos-sortable-header & sortable
The onos-sortable-header directive injects a click handler into every <td> element in the header that has a sortable attribute defined (see table.js for details).
The handler toggles the sort state between ascending and descending sort direction, as well as inserting the sort direction icons (up and down arrows) into the element. In addition, a sort request event is fired off to the server to re-fetch the table data, sorted with the new criteria.
Table Column Options
The first thing to note about the table columns is that the column headers use td tags (not th tags).
Columns may be labeled, or have no label at all (e.g. for columns with icons). The following table lists the possible options to be applied to a column:
|attribute col-width with pixel value||Sets column to that specific width in pixels|
|class||Sets column width to a good size for icons|
|attribute colId with value||Used to identify columns for sorting in ascending or descending order|
|attribute without value||Allows that column to be sortable|
See the following code snippet for an example:
A typical table body might look something like this:
The first <tr> element is made visible only if there are no rows of table data.
The second <tr> element is a pattern that is used repeatedly by Angular to create a row for every element in the tableData variable (defined on our controller scope). Note the icon column <td> is classed with "table-icon" so that it is sized correctly.
Table Row Options
If you wish to create a table where one item spans multiple rows, you can specify your data <tr> elements to look something like this:
Note the use of the ng-repeat-start directive in the first row, and the ng-repeat-end directive in the last.