xtrareports-404999-web-reporting-react-reporting-document-viewer-customization-custom-parameter-editor-in-viewer.md
This topic describes two ways to customize a standard parameter editor in the Web Document Viewer:
View Example: Customize Parameter Editor in the Web Document Viewer
Use the CustomizeParameterEditors event to change the display format and set validation rules for parameters.
The code snippets in the sections below remove the unnecessary time part from the DateTime editor and prevent users from entering a date earlier than the specified date.
Use the extendedOptions property to customize the DateBox editor options.
const onCustomizeParameterEditors = React.useCallback(({ args }: { args: any }): void => {
if (args.parameter.type === 'System.DateTime') {
args.info.editor = {...args.info.editor};
args.info.editor.extendedOptions = {
...args.info.editor.extendedOptions,
type: 'date',
displayFormat: 'dd-MMM-yyyy'
};
...
}, []);
Use the validationRules property to add rules to validate the value entered in the editor.
const onCustomizeParameterEditors = React.useCallback(({ args }: { args: any }): void => {
if (args.parameter.type === 'System.DateTime') {
...
args.info.validationRules = [{
type: "range",
min: new Date(1990, 0, 1),
message: "No data available prior to the year 1990."
}];
...
}, []);
The customized parameter editor appears as follows:
This section contains an example of a custom editor for the p_employeeID parameter that identifies an employee. The custom editor displays the expandable employee hierarchy and information about each employee.
Use the DevExtreme TreeList component as a template for the Employee ID parameter’s value editor.
The data source for the Tree List editor is a list of Employee objects created on the server and serialized to JSON.
The custom parameter editor is shown in the following image:
Follow the steps below to implement a custom value editor:
Create the Employee class.
Add a controller action that creates JSON data for the parameter editor.
Define a custom editor template with the Tree List editor.
To register the template, pass the template name and the template itself to the templateEngine.setTemplate method:
In the CustomizeParameterEditors event handler, set the header property to the template name for the p_employeeID parameter:
Handle the CustomizeParameterEditors event.