new (require("nmodule/webEditors/rc/wb/table/tree/TreeTableModel"))(params)
API Status: Development
A TableModel backed by a TreeNode. Each Row in the table must also be
backed by a TreeNode.
You should not typically call this constructor directly - use the .make()
method instead.
Extends:
Parameters:
| Name | Type | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
params |
Object |
Properties
|
Example
//when deciding which columns to use in the model, remember that rows
//will return the actual values via getSubject(), so ordinary
//Columns/MgrColumns can be used. custom column types can call
//row.getTreeNode() if necessary.
TreeTableModel.make({
columns: [
new PropertyMgrColumn('prop1'),
new PropertyMgrColumn('prop2')
]
});
//when inserting, values must be TreeNodes.
treeTableModel.insertRows(components.map(function (comp) {
var node = new TreeNode('component:' + comp.getName());
node.value = function () { return comp; };
return node;
});
Methods
-
<static> make(params)
-
Create a new
TreeTableModelinstance.Parameters:
Name Type Description paramsObject Properties
Name Type Description nodemodule:nmodule/webEditors/rc/wb/tree/TreeNode the root
node backing this modelReturns:
promise to be resolved with the new
TreeTableModelinstance, containing
one row per child node of the root node passed in- Type
- Promise.<module:nmodule/webEditors/rc/wb/table/tree/TreeTableModel>
-
clearRows()
-
Remove all rows from the model.
Will trigger a
rowsRemovedtinyevent, with
parameters:rowsRemoved: the rows that were removedindices: the original indices of the rows that were removed
- Inherited From:
Returns:
- Type
- Promise
-
collapse(row)
-
Get child nodes of the given
Row'sTreeNodeand remove their
correspondingRows.Parameters:
Name Type Description rowmodule:nmodule/webEditors/rc/wb/table/tree/TreeNodeRow Returns:
promise to be resolved with an array of the rows that were removed
- Type
- Promise.<Array.<module:nmodule/webEditors/rc/wb/table/model/Row>>
-
expand(row)
-
Get child nodes of the given
Row'sTreeNodeand insert newRows for
each one.Parameters:
Name Type Description rowmodule:nmodule/webEditors/rc/wb/table/tree/TreeNodeRow Returns:
promise to be resolved with an array of the inserted rows
- Type
- Promise.<Array.<module:nmodule/webEditors/rc/wb/table/tree/TreeNodeRow>>
-
getColumn(name)
-
Get the column in this model matching the given name.
Parameters:
Name Type Description nameString - Inherited From:
Returns:
the matching
column, ornullif not found -
getColumnIndex(column)
-
Get the index of the given column.
Parameters:
Name Type Description columnmodule:nmodule/webEditors/rc/wb/table/model/Column Returns:
the column's index, or -1 if not found
- Type
- number
-
getColumns( [flags])
-
Get the current set of columns, optionally filtered by flags.
Parameters:
Name Type Argument Description flagsNumber <optional>
if given, only return columns that have these
flags.Returns:
- Type
- Array.<module:nmodule/webEditors/rc/wb/table/model/Column>
-
getDepth(row)
-
Get the depth of this
Row'sTreeNodefrom theTreeTableModel's root
node. A direct child of the root will have a depth of 0, etc.Parameters:
Name Type Description rowmodule:nmodule/webEditors/rc/wb/table/model/Row Returns:
the depth of the
Row, ornullif the depth could
not be determined (e.g. theRowis not actually contained in this model).- Type
- number | null
-
getEditableColumns()
-
Return all columns with the
EDITABLEflag set.Returns:
- Type
- Array.<module:nmodule/webEditors/rc/wb/table/model/Column>
-
getRootNode()
-
Get the root node backing this
TreeTableModel.Returns:
-
getRowIndex(row)
-
Get the index of the given row.
Parameters:
Name Type Description rowmodule:nmodule/webEditors/rc/wb/table/model/Row Returns:
the row's index, or -1 if not found
- Type
- number
-
getRows()
-
Get the current set of rows.
- Inherited From:
Returns:
- Type
- Array.<module:nmodule/webEditors/rc/wb/table/model/Row>
-
getValueAt(x, y)
-
Ask the column at the given index for the value from the row at the
given index.Parameters:
Name Type Description xNumber column index
yNumber row index
Returns:
promise to be resolved with the value
- Type
- Promise
-
insertColumns(toInsert [, index])
-
Add new columns to the model. Will trigger a
columnsAddedtinyevent.Parameters:
Name Type Argument Description toInsertArray.<module:nmodule/webEditors/rc/wb/table/model/Column> indexNumber <optional>
index to insert the columns; will append to the
end if omittedReturns:
promise to be resolved if the insert is
successful- Type
- Promise
-
insertRows(toInsert [, index])
-
Add new rows to the model. If non-
Rowinstances are given, they will be
converted toRows usingmakeRow().If a row filter has been set to a non null function the index passed to this
function will be relative to the resulting filtered array returned from getRows().Will trigger a
rowsAddedtinyevent.Parameters:
Name Type Argument Description toInsertArray.<(module:nmodule/webEditors/rc/wb/table/model/Row|*)> indexNumber <optional>
index to insert the rows; will append to the
end if omittedReturns:
promise to be resolved if the insert is
successful- Type
- Promise
-
isExpandable(row)
-
Return true if the
Row'sTreeNodemight have child nodes.Parameters:
Name Type Description rowmodule:nmodule/webEditors/rc/wb/table/tree/TreeNodeRow Returns:
- Type
- boolean
-
isExpanded(row)
-
Return true if the given
Rowis marked as expanded.Parameters:
Name Type Description rowmodule:nmodule/webEditors/rc/wb/table/model/Row Returns:
- Type
- boolean
-
makeRow(subject)
-
Create a new
Rowinstance with aTreeNodeas the subject.Parameters:
Name Type Description subjectmodule:nmodule/webEditors/rc/wb/tree/TreeNode Returns:
-
removeColumns(toRemove [, end])
-
Remove columns from the model. Will trigger a
columnsRemovedtinyevent.Parameters:
Name Type Argument Description toRemoveArray.<module:nmodule/webEditors/rc/wb/table/model/Column> | Number the columns to remove; or, start index
endNumber <optional>
end index
Returns:
promise to be resolved if the remove is
successful- Type
- Promise
-
removeRows(toRemove [, end])
-
Remove rows from the model. Will trigger a
rowsRemovedtinyevent, with
parameters:rowsRemoved: the rows that were removedindices: the original indices of the rows that were removed
If a row filter has been set to a non null function any indices passed to this
function will be relative to the resulting filtered array returned from getRows().Note that
rowsRemovedandindiceswill always be sorted by their
original index in the model's rows, regardless of the order of rows passed
to theremoveRowsfunction.Parameters:
Name Type Argument Description toRemoveArray.<module:nmodule/webEditors/rc/wb/table/model/Row> | Number the rows to remove; or, start index
end<optional>
end index
Returns:
promise to be resolved if the remove is
successful- Type
- Promise
-
setRowFilter(rowFilterFunction)
-
Filter the table's rows according to the given filter function. Setting
therowFilterFunctiontonullwill remove the current filter and
reset the table model to display all rows.Will trigger a
rowsFilteredtinyevent.Remember that
Array#filteris synchronous, so if the filter needs to use
any data that is asynchronously retrieved, the async work must be performed
before the filter so that the filter function can work synchronously.Parameters:
Name Type Description rowFilterFunctionfunction standard array filter function
Throws:
-
if a non-Function is given
- Type
- Error
Returns:
- Type
- Promise
-
-
sort(sortFunction)
-
Sort the table's rows according to the given sort function. Emits a
rowsReorderedevent.Remember that
Array#sortis synchronous, so if the sort needs to use
any data that is asynchronously retrieved, the async work must be performed
before the sort so that the sort function can work synchronously.Parameters:
Name Type Description sortFunctionfunction standard array sort function to receive
twoRowinstances- Inherited From:
Throws:
-
if a non-Function is given
- Type
- Error
-
toggle(row)
-
Collapse the row if it is expanded, and vice versa.
Parameters:
Name Type Description rowmodule:nmodule/webEditors/rc/wb/table/model/Row Returns:
- Type
- Promise