Article

Filtering detail records based on selected record of other detail

Main detail code

define("UsrMasterDetail", [], function() {
    return {
        entitySchemaName: "Country",
        messages: {
            "RelatedDetailUpdateFilter": {
                mode: this.Terrasoft.MessageMode.PTP,
                direction: this.Terrasoft.MessageDirectionType.PUBLISH
            }
        },
        methods: {
            onActiveRowChange: function() {
                var activeRow = this.get("ActiveRow");
                var masterDetailRecordId = typeof activeRow === "object" ? activeRow && activeRow.value : activeRow;
                this.sandbox.publish("RelatedDetailUpdateFilter", masterDetailRecordId,
                    [this.sandbox.id.replace(this.name, "MasterDetailRecordId")]);
                this.callParent(arguments);
            }
        }
    };
});

Related detail code

define("UsrRelatedDetail", [], function() {
    return {
        entitySchemaName: "City",
        messages: {
            "RelatedDetailUpdateFilter": {
                mode: this.Terrasoft.MessageMode.PTP,
                direction: this.Terrasoft.MessageDirectionType.SUBSCRIBE
            }
        },
        attributes: {
            "MasterDetailRecordId": {
                "dataValueType": this.Terrasoft.DataValueType.GUID
            }
        },
        methods: {
            init: function() {
                this.sandbox.subscribe("RelatedDetailUpdateFilter", function(masterDetailRecordId) {
                    this.set("MasterDetailRecordId", masterDetailRecordId);
                    this.setFilterByMasterRecord(masterDetailRecordId);
                    this.reloadGridData();
                }, this, [this.sandbox.id.replace(this.name, "MasterDetailRecordId")]);
                this.callParent(arguments);
            },
            loadGridData: function() {
                if (this.get("MasterDetailRecordId")) {
                    this.callParent(arguments);
                } else {
                    this.onGridDataLoaded({success: true});
                }
            },
            setFilterByMasterRecord: function(masterDetailRecordId) {
                var filters = this.get("Filter");
                filters.removeByKey("FilterByMasterDetail");
                if (masterDetailRecordId) {
                    filters.add("FilterByMasterDetail", this.Terrasoft.createColumnFilterWithParameter(
                        this.Terrasoft.ComparisonType.EQUAL, "Country", masterDetailRecordId));
                }
            }
        }
    };
});

Insert details into page

define("ContactPageV2", [], function() {
    return {
        entitySchemaName: "Contact",
        details: /**SCHEMA_DETAILS*/{
            "UsrMasterDetail": {
                "schemaName": "UsrMasterDetail",
                "filterMethod": "getGlbDetailFilter"
            },
            "UsrRelatedDetail": {
                "schemaName": "UsrRelatedDetail",
                "filterMethod": "getGlbDetailFilter"
            }
        }/**SCHEMA_DETAILS*/,
        diff: /**SCHEMA_DIFF*/[
            {
                "operation": "insert",
                "name": "UsrMasterDetail",
                "values": {
                    "itemType": this.Terrasoft.ViewItemType.DETAIL
                },
                "parentName": "GeneralInfoTab",
                "propertyName": "items"
            },
            {
                "operation": "insert",
                "name": "UsrRelatedDetail",
                "values": {
                    "itemType": this.Terrasoft.ViewItemType.DETAIL
                },
                "parentName": "GeneralInfoTab",
                "propertyName": "items"
            }
        ]/**SCHEMA_DIFF*/,
        methods: {
            getGlbDetailFilter: function() {
                var filterGroup = new this.Terrasoft.createFilterGroup();
                return filterGroup;
            }
        }
    };
});

Result:

Share

0 comments
Log in or register to comment