Scenario
There are custom mail merge templates for the Employee class. Each template relates to a specific department. When you select an employee from the Sales department, the ShowInDocument Action displays only corresponding templates.
Solution
The Solution is available starting with version 18.1.7.
1. In the YourSolutionName.Module project, extend the DevExpress.Persistent.BaseImpl.RichTextMailMergeData class (or DevExpress.Persistent.BaseImpl.EF.RichTextMailMergeData if you use Entity Framework) with the Department property and override the GetAdditionalMailMergeInfo method to return the Department instance.
C#using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
namespace FilterMailMergeTemplateExample.Module.BusinessObjects {
public class CustomMailMergeData : RichTextMailMergeData {
public CustomMailMergeData(Session session) : base(session) { }
public Department Department {
get { return GetPropertyValue<Department>(nameof(Department)); }
set { SetPropertyValue(nameof(Department), value); }
}
public override object GetAdditionalMailMergeInfo() {
return Department;
}
}
}
2. Specify the CustomMailMergeData type as the RichTextMailMergeDataType option as described at Mail Merge.
3.1 In the YourSolutionName.Blazor.Server/YourSolutionName.Win projects, inherit the ShowInDocumentController class and override the FilterActionItems method as follows:
Blazor
C#using DevExpress.ExpressApp.Actions;
using dxTestSolution.Module.BusinessObjects;
using DevExpress.ExpressApp.Office;
using DevExpress.ExpressApp.Office.Blazor.Controllers;
using dxT1218062.Module.BusinessObjects;
namespace dxTestSolution.Blazor.Server.Controllers;
public class CustomShowInDocumentController : BlazorShowInDocumentController {
public CustomShowInDocumentController() : base() { }
protected override void FilterActionItems(IList<ChoiceActionItem> items) {
base.FilterActionItems(items);
if (View.ObjectTypeInfo.Type == typeof(ApplicationUser)) {
foreach (ChoiceActionItem item in items) {
Department department = ((MailMergeDataInfo)item.Data).AdditionalMailMergeInfo as Department;
if (department != null) {
item.Active["Filter"] = View.SelectedObjects.OfType<ApplicationUser>().All(employee => employee.Department != null && employee.Department.Name == department.Name);
}
}
}
}
}
WinForms
C#using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Office.Win;
using DevExpress.ExpressApp.Office;
using FilterMailMergeTemplateExample.Module.BusinessObjects;
using System.Collections.Generic;
using System.Linq;
namespace FilterMailMergeTemplateExample.Module.Win.Controllers {
public class CustomShowInDocumentController : ShowInDocumentController {
public CustomShowInDocumentController() : base() { }
protected override void FilterActionItems(IList<ChoiceActionItem> items) {
base.FilterActionItems(items);
if(View.ObjectTypeInfo.Type == typeof(Employee)) {
foreach(ChoiceActionItem item in items) {
Department department = ((MailMergeDataInfo)item.Data).AdditionalMailMergeInfo as Department;
if(department != null) {
item.Active["Filter"] = View.SelectedObjects.OfType<Employee>().All(employee => employee.Department != null && employee.Department.Name == department.Name);
}
}
}
}
}
}