Article

Add custom DataView in Section

Add new DataView in Contact Section (only contacts with B2B type)

define("ContactSectionV2", ["GlbClientConstants"], function(clientConstants) {
    return {
        entitySchemaName: "Contact",
        details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
        attributes: {},
        methods: {
            getDefaultDataViews: function() {
                var baseDataViews = this.callParent(arguments);
                baseDataViews.GridDataViewB2B = {
                    name: "GridDataViewB2B",
                    caption: this.get("Resources.Strings.B2BButtonCaption"), // Section header
                    hint: this.get("Resources.Strings.B2BButtonCaption"), // Hint for button
                    icon: this.get("Resources.Images.B2BDataViewIcon") // Image for button
                };
                return baseDataViews;
            },
            loadActiveViewData: function() {
                var activeViewName = this.getActiveViewName();
                if (activeViewName === "GridDataViewB2B") {
                    this.loadGridData();
                }
                this.callParent(arguments);
            },
            loadGridDataView: function(loadData) {
                var gridData = this.getGridData();
                if (gridData && loadData) {
                    gridData.clear();
                }
                this.setViewFilter(this.get("ActiveViewName"));
                this.reloadGridColumnsConfig(false);
                this.reloadSummaryModule();
                this.callParent(arguments);
            },
            loadGridDataViewB2B: function(loadData) { // "load" + DataView.name
                this.loadGridDataView(loadData);
            },
            setActiveView: function(activeViewName) {
                this.callParent(arguments);
                if (activeViewName === "GridDataViewB2B") {
                    this.set("IsGridDataViewVisible", true);
                }
            },
            setViewFilter: function(activeViewName) { // Add filter for your "DataView"
                var sectionFilters = this.get("SectionFilters");
                if (activeViewName === "GridDataViewB2B") {
                    sectionFilters.add("FilterB2BType", this.Terrasoft.createColumnFilterWithParameter(
                        this.Terrasoft.ComparisonType.EQUAL, "Type", clientConstants.ContactTypes.B2B));
                } else {
                    sectionFilters.removeByKey("FilterB2BType");
                }
            }
        }
    };
});

Share

2 comments

How to create GridDataViewB2B? Is it a schema of the section view model?

Thank you

You don't need to create a schema. The GridDataViewB2B is created in the getDefaultDataViews function via native js (https://prnt.sc/pl1tvo).

Log in or register to comment