Skip to main content
All docs
V24.1

CustomWizardData Class

Contains custom data obtained from the Report Wizard pages.

Namespace: DevExpress.XtraReports.Web.ReportDesigner.DataContracts

Assembly: DevExpress.XtraReports.v24.1.Web.dll

NuGet Package: DevExpress.Web.Reporting.Common

Declaration

[DataContract]
public class CustomWizardData

Remarks

The CustomWizardData class is used to pass custom data from the Report Wizard page to the ReportWizardCustomizationService methods.

The following JavaScript code stores data that the user entered on the custom page. The data is placed in the session.

function beforeInitializeWizard(args) {
    class LabelPage extends DevExpress.Analytics.Wizard.WizardPageBase {
        canNext() {
            return false;
        }

        canFinish() {
            return true;
        }

        commit() {
            return $.Deferred().resolve({
                Label1: this.label1Value(),
                Label2: this.label2Value(),
                Label3: this.label3Value(),
                ReportName: this.label4Value(),
            }).promise();
        }

        label1Value = ko.observable('Label1');
        label2Value = ko.observable('Label2');
        label3Value = ko.observable('Label3');
        label4Value = ko.observable('SomeReportName');
    }
    args.wizard.pageFactory.registerMetadata('CustomLabelPage', {
        create: () => new LabelPage(),
        getState: (state) => state,
        setState: (data, state) => {
            state.customData = JSON.stringify(data);
        },
        resetState: (state, defaultState) => {
            state.customData = undefined;
        },
        template: 'wizard-labels-page',
        navigationPanelText: 'Specify label values'
    });
}

function afterInit(args) {
    const defaultGetNextPageId = args.wizard.iterator.getNextPageId;
    args.wizard.iterator.getNextPageId = function (pageId) {
        if(pageId === 'selectReportTypePage' && args.wizard.iterator._getCurrentState().reportTemplateID === 'CustomLabelReport') {
            return 'CustomLabelPage';
        } else {
            return defaultGetNextPageId.apply(this, [pageId]);
        }
    };
}

function CustomizeReportWizard(s, e) {
    if(e.Type === 'ReportWizard') {
        DevExpress.Analytics.Widgets.Internal.addToBindingsCache('dxTextBox: { value: label4Value }', function($context, $element) { return { 'dxTextBox': function() { return { 'value': $context.$data.label4Value } } } });
        DevExpress.Analytics.Widgets.Internal.addToBindingsCache('dxTextBox: { value: label1Value }', function($context, $element) { return { 'dxTextBox': function() { return { 'value': $context.$data.label1Value } } } });
        DevExpress.Analytics.Widgets.Internal.addToBindingsCache('dxTextBox: { value: label2Value }', function($context, $element) { return { 'dxTextBox': function() { return { 'value': $context.$data.label2Value } } } });
        DevExpress.Analytics.Widgets.Internal.addToBindingsCache('dxTextBox: { value: label3Value }', function($context, $element) { return { 'dxTextBox': function() { return { 'value': $context.$data.label3Value } } } });
        e.Wizard.events.addHandler('beforeInitialize', beforeInitializeWizard);
        e.Wizard.events.addHandler('afterInitialize', afterInit);
        e.Wizard.events.addHandler('beforeFinish', (result) => {
            result.state.customData = result.state.customData || 'CustomizeEmptyReport';
        });
    }
}

The following code processes custom data in the ReportWizardCustomizationService.TryCreateCustomReport method:

public override XtraReport TryCreateCustomReport(XtraReportModel model, object dataSource, string dataMember, CustomWizardData customWizardData, XtraReport report) {
    if (Enum.TryParse(customWizardData.ReportTemplateID, out CustomReportType customReportType)) {
        if (customReportType == CustomReportType.InstantReport) {
            return new InstantReport() {
                Name = customWizardData.ReportTemplateID,
                DisplayName = customWizardData.ReportTemplateID
            };
        }
        else if (customReportType == CustomReportType.CustomLabelReport) {
            var labelReport = new LabelReport();
            labelReport.ApplyCustomData(customWizardData.Data);
            return labelReport;
        }
    }
    return base.TryCreateCustomReport(model, dataSource, dataMember, customWizardData, report);
}

The following code deserializes and applies custom data to the report:

    public partial class LabelReport : DevExpress.XtraReports.UI.XtraReport {
    // ...
        public void ApplyCustomData(string customDataJson) {
            Labels labels = JsonSerializer.Deserialize<Labels>(customDataJson);
            xrLabel1.Text = labels.Label1;
            xrLabel2.Text = labels.Label2;
            xrLabel3.Text = labels.Label3;
            Name = labels.ReportName;
            DisplayName = labels.ReportName;
        }
    }
    // ...
}

View Example: Reporting for Web (ASP.NET MVC, ASP.NET Core and Angular) - How to Use the Report Wizard Customization API and Hide Data Source Actions in Report Designer

Inheritance

Object
CustomWizardData
See Also