TableSheet supports some built-in formulas that can be used with hierarchy data.
When the data source is hierarchical, a formula can be configured for data fields in the schema, and the formula only be invoked when the record has children.
This means that the value for the parent record is summarized, and the value from the child record are in the same field when retrieving.
The hierarchy summary field options:
interface GC.Data.IDataSourceOption {
//others options...
schema?: {
hierarchy: {
summaryFields: GC.Data.IHierarchySummaryFieldCollection // define the formulas for the fields
//others options...
}
//others options...
}
}
interface GC.Data.IHierarchySummaryFieldCollection {
[key: string]: string; // the key is the field name, and the value is the formula
}
The following is a sample that shows how to configure the hierarchy summary fields:
var table = dataManager.addTable("Table", {
schema: {
hierarchy: {
type: 'Parent',
column: 'parent',
summaryFields: {
'budget':'=SUM(CHILDREN(1,"budget"))'
}
},
columns: {
id: {
isPrimaryKey: true,
},
budget: { dataType: 'number' }
},
}
});
var view = table.addView("View",[
{ value: "id" },
{ value: "budget" },
])
The Built-in Formulas
The built-in formulas can be used in the hierarchy summary fields or in the calculation column when it’s in the hierarchy:
CHILDREN
This formula is for retrieving the value that is specified by the [fieldName] of the children that are [levelOffset] steps away from the parent.
If the level offset is bigger than the interval between the current record and the lowest children, the values are from the children that are not parents.
CHILDREN(levelOffset, fieldName)
ONLYCHILDREN
This formula is for retrieving the value that is specified by [fieldName] of the children that are not parents.
ONLYCHILDREN(fieldName)
PARENT
This formula is for retrieving the value that is specified by [fieldName] of the parent that are [levelOffset] steps away from the current record.
If the level offset is bigger than the interval between the current record and the highest parent, the value is from the highest parent. However if the current record is the highest parent, nothing will be retrieved.
PARENT(levelOffset, fieldName)
LEVEL
This formula is for retrieving the level of the current record.
LEVEL()
LEVELROWNUMBER
This formula is for retrieving the row number of the current record under the parent scope.
LEVELROWNUMBER()
Submit and view feedback for