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:

editor = document.editors[0] visibleColumns = columns.map(function(column){ if (editor.visibilityOfColumn(column)){return column} })
editor = document.editors[0] visibleTextColumns = columns.map(function(column){ if (editor.visibilityOfColumn(column)){ if (column.type === Column.Type.Text){return column} } })
columnTitles = columns.map(function(column){return column.title})

Column Methods (functions)

Here are the methods used with an instance of the Column class:

Column Array Methods (functions)

Here are the methods used with an array of items of the Column class:

column = columns.byTitle('STATS') 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:

Column.Type Instance Properties

The Column.Type instance properties are the value for an instance of the type property of the Column class:

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

var editor = document.editors[0] var targetColumn = columns.byTitle('STATS') var summaryType = Column.Summary.Maximum if (targetColumn && targetColumn.type === Column.Type.Number){ editor.setSummaryForColumn(targetColumn, summaryType) }

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.

var tree = document.outline var editor = document.editors[0] tree.addColumn( Column.Type.Number, editor.afterColumn(tree.outlineColumn), function(column){ column.title = 'Q1' editor.setSummaryForColumn(column, Column.Summary.Total) } )
omnioutliner://localhost/omnijs-run?script=try%7Btree%20%3D%20document%2Eoutline%0Aeditor%20%3D%20document%2Eeditors%5B0%5D%0Atree%2EaddColumn%28%0A%09Column%2EType%2ENumber%2C%0A%09editor%2EafterColumn%28tree%2EoutlineColumn%29%2C%20%0A%09function%28column%29%7B%0A%09%09column%2Etitle%20%3D%20%27Q1%27%0A%09%09editor%2EsetSummaryForColumn%28column%2C%20Column%2ESummary%2ETotal%29%0A%09%7D%0A%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
var tree = document.outline var editor = document.editors[0] var newCol = tree.addColumn( Column.Type.Number, editor.afterColumn(null), null ) newCol.title = 'Q2' editor.setSummaryForColumn(newCol, Column.Summary.Total)
omnioutliner://localhost/omnijs-run?script=try%7Bvar%20tree%20%3D%20document%2Eoutline%0Avar%20editor%20%3D%20document%2Eeditors%5B0%5D%0Avar%20newCol%20%3D%20tree%2EaddColumn%28%0A%09Column%2EType%2ENumber%2C%0A%09editor%2EafterColumn%28null%29%2C%20%0A%09null%0A%29%0AnewCol%2Etitle%20%3D%20%27Q2%27%0Aeditor%2EsetSummaryForColumn%28newCol%2C%20Column%2ESummary%2ETotal%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D

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:

var column = columns.byTitle('Q4') if (column && column.type === Column.Type.Number){ var cellValues = rootItem.children.map(item => { return item.valueForColumn(column) }) var total = Decimal.zero cellValues.forEach(value => total = total.add(value)) console.log(Number(total.toString())) }
tree = document.outline editor = document.editors[0] tree.addColumn( Column.Type.Number, editor.afterColumn(columns[columns.length]), function(column){ column.title = 'Q1' editor.setSummaryForColumn(column, Column.Summary.Total) editor.setWidthForColumn(column, 64) column.style.set(Style.Attribute.ParagraphAlignment, TextAlignment.Right) column.formatter = Formatter.Decimal.plain } )

A plug-in for appending a new numeric column to the end of the outline:

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.add-numeric-column", "description": "Add a new numeric column to the end of the outline.", "label": "Add Numeric Column", "shortLabel": "Add Numeric Column" }*/ var _ = function(){ var action = new PlugIn.Action(function(selection, sender){ // CONSTRUCT THE FORM var inputForm = new Form() // CREATE FORM ELEMENTS: TEXT INPUT textInputField = new Form.Field.String( "columnTitle", "Title", null ) // ADD THE ELEMENTS TO THE FORM inputForm.addField(textInputField) // DISPLAY THE FORM DIALOG var formPromise = inputForm.show("Enter the column title:","Add") // VALIDATE FORM CONTENT inputForm.validate = function(formObject){ // EXTRACT VALUES FROM THE FORM’S VALUES OBJECT columnTitle = formObject.values['columnTitle'] // HAS TEXT BEEN ENTERED IN THE INPUT FIELD? textStatus = (columnTitle && columnTitle.length > 0) ? true:false // RETURN VALIDATION return textStatus } // PROCESS FORM RESULTS formPromise.then(function(formObject){ // EXTRACT VALUES FROM THE FORM’S VALUES OBJECT var columnTitle = formObject.values['columnTitle'] // CREATE AND FORMAT THE COLUMN tree = document.outline editor = document.editors[0] tree.addColumn( Column.Type.Number, editor.afterColumn(columns[columns.length]), function(column){ column.title = columnTitle editor.setSummaryForColumn(column, Column.Summary.Total) editor.setWidthForColumn(column, 64) column.style.set(Style.Attribute.ParagraphAlignment, TextAlignment.Right) column.formatter = Formatter.Decimal.plain } ) }) // PROCESS FORM CANCELLATION formPromise.catch(function(err){ console.log("form cancelled", err.message) }) }); action.validate = function(selection, sender){ // validation code // selection options: columns, document, editor, items, nodes, outline, styles return true }; return action; }(); _;

A plug-in for adding a new row with a populated creation date field:

/*{ "type": "action", "targets": ["omnioutliner"], "author": "Otto Automator", "identifier": "com.omni-automation.oo.new-row-with-date", "version": "1.0", "description": "Cretes a new row with the current date inserted into a Date column.", "label": "New Row with Date", "shortLabel": "New Row with Date" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code var columnTitle = "Date" var dateColumn = columns.byTitle(columnTitle) if (!dateColumn){ // CREATE AND FORMAT THE COLUMN var tree = document.outline var editor = document.editors[0] tree.addColumn( Column.Type.Date, editor.afterColumn(columns[columns.length]), function(column){ column.title = columnTitle editor.setWidthForColumn(column, 72) column.style.set(Style.Attribute.ParagraphAlignment, TextAlignment.Center) column.formatter = Formatter.Date.withStyle(Formatter.Date.Style.Short) } ) dateColumn = columns.byTitle(columnTitle) } // CREATE AND POPLULATE NEW ROW var newRow = rootItem.addChild() newRow.setValueForColumn(new Date(), dateColumn) }); action.validate = function(selection, sender){ // validation code // selection options: columns, document, editor, items, nodes, outline, styles return true }; return action; })();
UNDER CONSTRUCTION

This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.

DISCLAIMER