Column
Just as rows describe how your content is oriented horizontally in the outline, Columns describe how it is grouped vertically.
All OmniOutliner documents must have at least one column. The default column created for a new document is the Topic column, which contains content in rich text format by default.
The Topic column is also the only column in the outline that can organize its rows hierarchically; when organization in the Topic column changes, content in additional columns goes along for the ride.
Column Properties
Here are the properties of an instance of the Column class:
enumeration (Enumeration or nil r/o) • If the column is a of type Column.Type.Enumeration, this returns the Enumeration of members defined for use in cells in that column.
formatter (Formatter or nil) • Controls the format used to display values displayed in this column. Only some column types allow formatters, and the type of the formatter must match the type of data in the column (for example, a column with a type of Column.Type.Number should have a formatter of type Formatter.Number.
outline (Outline r/o) • No documentation available.
style (Style r/o) • The style used for cells in this column (which may be overridden by individual rows and their cells).
textAlignment (TextAlignment) • Controls the TextAlignment of the contents of cells in the Column.
title (String) • No documentation available.
type (Column.Type r/o) • No documentation available.
Get the Visible Columns | ||
01 | editor = document.editors[0] | |
02 | visibleColumns = columns.map(function(column){ | |
03 | if (editor.visibilityOfColumn(column)){return column} | |
04 | }) |
Get Visible Text Columns | ||
01 | editor = document.editors[0] | |
02 | visibleTextColumns = columns.map(function(column){ | |
03 | if (editor.visibilityOfColumn(column)){ | |
04 | if (column.type === Column.Type.Text){return column} | |
05 | } | |
06 | }) |
Getting Column Titles | ||
01 | columnTitles = columns.map(function(column){return column.title}) |
Column Methods (functions)
Here are the methods used with an instance of the Column class:
remove() • Removes a previously added column from its outline. Pre-defined columns like the outline column, note column, and status column cannot be removed. Calling remove() on them will throw an error.
Column Array Methods (functions)
Here are the methods used with an array of items of the Column class:
byTitle(titleString) (--> Column or nil) • Return the first Column having the given title, or null if no such column is in the array.
Locating Column by Title | ||
01 | column = columns.byTitle('STATS') | |
02 | if (column == null){throw new Error('No column exists.')} |
Column.Type Class Properties
The Column.Type class properties are the value for the type property of the Column class:
Checkbox (Column.Type r/o) • No documentation available.
Date (Column.Type r/o) • No documentation available.
Duration (Column.Type r/o) • No documentation available.
Enumeration (Column.Type r/o) • No documentation available.
Number (Column.Type r/o) • No documentation available.
Text (Column.Type r/o) • No documentation available.
Column.Type Instance Properties
The Column.Type instance properties are the value for an instance of the type property of the Column class:
identifier (String r/o) • No documentation available.
Column.Summary
A Summary can be applied for a Column in a given Editor using its setSummaryForColumn() function. When there is a summary set, it defines a rule for calculating a value to display for a parent row, given the values in its children. Note that this calculated value is not stored in the parent Item itself and instead can be accessed by the TreeNode representing the Item within the Editor.
Column.Summary Instance Properties
AverageLeaves (Column.Summary r/o) • Calculate the average value over the entries in the descendant Items that themselves have no children.
Hidden (Column.Summary r/o) • Hide the value in rows displayed for Items that have children.
Maximum (Column.Summary r/o) • Display the maximum value over the children of each Item.
Minimum (Column.Summary r/o) • Display the minimum value over the children of each Item.
State (Column.Summary r/o) • For Checkbox columns, calculate the state of the checkbox based off the state of the children. If all children are checked or unchecked, the parent will display a check as well. If there is a mix of children states, the parent will display a mixed state, indicated by a “-” character.
Total (Column.Summary r/o) • Display the total of the values in the children of each Item.
Set Column Summary Type | ||
01 | var editor = document.editors[0] | |
02 | var targetColumn = columns.byTitle('STATS') | |
03 | var summaryType = Column.Summary.Maximum | |
04 | if (targetColumn && targetColumn.type === Column.Type.Number){ | |
05 | editor.setSummaryForColumn(targetColumn, summaryType) | |
06 | } |
Adding a Column to an Outline
Here’s are two versions of script that adds a numeric column (named “Q1”) after the outline column. The scripts use the addColumn() method of the Column class. The first version includes a passed-in function that names the created column. The second version does not include a passed-in function and instead titles the column after it has been created.
Add Numeric Column to Outline | ||
01 | var tree = document.outline | |
02 | var editor = document.editors[0] | |
03 | tree.addColumn( | |
04 | Column.Type.Number, | |
05 | editor.afterColumn(tree.outlineColumn), | |
06 | function(column){ | |
07 | column.title = 'Q1' | |
08 | editor.setSummaryForColumn(column, Column.Summary.Total) | |
09 | } | |
10 | ) |
Add Numeric Column to Outline | ||
01 | var tree = document.outline | |
02 | var editor = document.editors[0] | |
03 | var newCol = tree.addColumn( | |
04 | Column.Type.Number, | |
05 | editor.afterColumn(null), | |
06 | null | |
07 | ) | |
08 | newCol.title = 'Q2' | |
09 | editor.setSummaryForColumn(newCol, Column.Summary.Total) |
Also note in the above example that since a null value is entered rather than an instance of the EditorColumnPosition class for the parameter of the afterColumn(…) method, the new column is created after the last column.
Sum a Numeric Column
Here’s script that uses the valueForColumn(…) function of the Editor class to sum the cells of a numeric column:
Sum Numeric Column | ||
01 | var column = columns.byTitle('Q4') | |
02 | if (column && column.type === Column.Type.Number){ | |
03 | var cellValues = rootItem.children.map(item => { | |
04 | return item.valueForColumn(column) | |
05 | }) | |
06 | var total = Decimal.zero | |
07 | cellValues.forEach(value => total = total.add(value)) | |
08 | console.log(Number(total.toString())) | |
09 | } |
A plug-in for appending a new numeric column to the end of the outline:
Append Numeric Column | ||
01 | /*{ | |
02 | "type": "action", | |
03 | "targets": ["omnioutliner"], | |
04 | "author": "Otto Automator", | |
05 | "identifier": "com.omni-automation.oo.add-numeric-column", | |
06 | "description": "Add a new numeric column to the end of the outline.", | |
07 | "label": "Append Numeric Column", | |
08 | "shortLabel": "Append Numeric Column" | |
09 | }*/ | |
10 | var _ = function(){ | |
11 | var action = new PlugIn.Action(function(selection, sender){ | |
12 | ||
13 | // CONSTRUCT THE FORM | |
14 | var inputForm = new Form() | |
15 | ||
16 | // CREATE FORM ELEMENTS: TEXT INPUT | |
17 | textInputField = new Form.Field.String( | |
18 | "columnTitle", | |
19 | "Title", | |
20 | null | |
21 | ) | |
22 | ||
23 | // ADD THE ELEMENTS TO THE FORM | |
24 | inputForm.addField(textInputField) | |
25 | ||
26 | // DISPLAY THE FORM DIALOG | |
27 | var formPromise = inputForm.show("Enter the column title:","Add") | |
28 | ||
29 | // VALIDATE FORM CONTENT | |
30 | inputForm.validate = function(formObject){ | |
31 | // EXTRACT VALUES FROM THE FORM’S VALUES OBJECT | |
32 | columnTitle = formObject.values['columnTitle'] | |
33 | // HAS TEXT BEEN ENTERED IN THE INPUT FIELD? | |
34 | textStatus = (columnTitle && columnTitle.length > 0) ? true:false | |
35 | // RETURN VALIDATION | |
36 | return textStatus | |
37 | } | |
38 | ||
39 | // PROCESS FORM RESULTS | |
40 | formPromise.then(function(formObject){ | |
41 | // EXTRACT VALUES FROM THE FORM’S VALUES OBJECT | |
42 | var columnTitle = formObject.values['columnTitle'] | |
43 | ||
44 | // CREATE AND FORMAT THE COLUMN | |
45 | tree = document.outline | |
46 | editor = document.editors[0] | |
47 | tree.addColumn( | |
48 | Column.Type.Number, | |
49 | editor.afterColumn(columns[columns.length]), | |
50 | function(column){ | |
51 | column.title = columnTitle | |
52 | editor.setSummaryForColumn(column, Column.Summary.Total) | |
53 | editor.setWidthForColumn(column, 64) | |
54 | column.style.set(Style.Attribute.ParagraphAlignment, TextAlignment.Right) | |
55 | column.formatter = Formatter.Decimal.plain | |
56 | } | |
57 | ) | |
58 | ||
59 | }) | |
60 | ||
61 | // PROCESS FORM CANCELLATION | |
62 | formPromise.catch(function(err){ | |
63 | console.log("form cancelled", err.message) | |
64 | }) | |
65 | ||
66 | }); | |
67 | ||
68 | action.validate = function(selection, sender){ | |
69 | // validation code | |
70 | // selection options: columns, document, editor, items, nodes, outline, styles | |
71 | return true | |
72 | }; | |
73 | ||
74 | return action; | |
75 | }(); | |
76 | _; |
A plug-in for adding a new row with a populated creation date field:
New Row with Date | ||
01 | /*{ | |
02 | "type": "action", | |
03 | "targets": ["omnioutliner"], | |
04 | "author": "Otto Automator", | |
05 | "identifier": "com.omni-automation.oo.new-row-with-date", | |
06 | "version": "1.0", | |
07 | "description": "Cretes a new row with the current date inserted into a Date column.", | |
08 | "label": "New Row with Date", | |
09 | "shortLabel": "New Row with Date" | |
10 | }*/ | |
11 | (() => { | |
12 | var action = new PlugIn.Action(function(selection, sender){ | |
13 | // action code | |
14 | var columnTitle = "Date" | |
15 | ||
16 | var dateColumn = columns.byTitle(columnTitle) | |
17 | if (!dateColumn){ | |
18 | // CREATE AND FORMAT THE COLUMN | |
19 | var tree = document.outline | |
20 | var editor = document.editors[0] | |
21 | tree.addColumn( | |
22 | Column.Type.Date, | |
23 | editor.afterColumn(columns[columns.length]), | |
24 | function(column){ | |
25 | column.title = columnTitle | |
26 | editor.setWidthForColumn(column, 72) | |
27 | column.style.set(Style.Attribute.ParagraphAlignment, TextAlignment.Center) | |
28 | column.formatter = Formatter.Date.withStyle(Formatter.Date.Style.Short) | |
29 | } | |
30 | ) | |
31 | dateColumn = columns.byTitle(columnTitle) | |
32 | } | |
33 | ||
34 | // CREATE AND POPLULATE NEW ROW | |
35 | var newRow = rootItem.addChild() | |
36 | newRow.setValueForColumn(new Date(), dateColumn) | |
37 | ||
38 | }); | |
39 | ||
40 | action.validate = function(selection, sender){ | |
41 | // validation code | |
42 | // selection options: columns, document, editor, items, nodes, outline, styles | |
43 | return true | |
44 | }; | |
45 | ||
46 | return action; | |
47 | })(); |
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.