Overriding a tree-level restriction
Overriding a tree-level restriction
Sample View: http://localhost:8080/archibus/schema/ab-products/solutions/parts/tree/ab-ex-tree-grouping.axvw
By default, the tree control applies the selected node primary key value(s) as a restriction to the next level. This is a good default, but some applications need a different behavior. For example, the tree may display distinct values of the
contact.contact_type
field on the first level, and contacts of the selected type on the next level.
Since these two levels are not related by a foreign key, they are not restricted properly. This problem can be avoided by overriding the tree-level restriction. This is done by overriding the
createRestrictionForLevel
function in the application code as shown below. This method creates a restriction for the next level that overrides the tree-level restriction.
View.createController('groupingTree', {
afterViewLoad: function() {
// override default createRestrictionForLevel() method of this tree control
// do it in afterViewLoad() to make sure the overridden method is used in tree control's initial data fetch
// the returned restriction will be used by the tree control as is, without any modifications
// if the method returns null, the tree control will use its default restriction
this.treeGrouping_parentTree.createRestrictionForLevel = function(parentNode, level) {
var restriction = null;
// in this example we want to override only restriction applied from the 1st to the 2nd level
// level 0 is the root node (invisible)
if (level == 1) {
var contactType = parentNode.data['contact.contact_type'];
restriction = new Ab.view.Restriction();
restriction.addClause('contact.contact_type', contactType, '=');
}
return restriction;
}
}
});
Overriding the c
reateRestrictionForLevel
function requires that your code applies restrictions for all tree levels. In tree views with many tree levels, youmay wish instead to keep the default restrictions applied by the tree control, but also add your own restriction clauses. For example, you can allow users to filter tree data.
// override the function that add restriction clauses to the tree level restriction
this.exTreeAfterGetData_pmpTree.updateRestrictionForLevel = function(parentNode, level, restriction) {
// for the Trades tree level
if (level === 2) {
// display only HVAC trades
restriction.addClause('pmpstr.res_id', 'HVAC', 'like');
}
};
// re-query tree data
this.exTreeAfterGetData_pmpTree.refresh();
// expand tree levels 0, 1, and 2
this.exTreeAfterGetData_pmpTree.expandAll(2);
If you apply a restriction to hide children nodes, you may also wish to not display parent nodes that have no visible children. To do so, set the
showNodesWithoutChildren
property of the tree panel:
this.exTreeAfterGetData_pmpTree.showNodesWithoutChildren = false;
The example code is in /schema/ab-products/solutions/parts/tree/ab-ex-tree-after-get-data.js .
.