Search This Blog

Thursday, October 19, 2017

How to group validation rules by a business type in Model Editor

If you want the same UI as in the screenshot below:


implement a few code lines in YourSolutionName.Module/Module.cs file, as follows:

using DevExpress.ExpressApp.ModelEditor;
using DevExpress.ExpressApp.Validation;
using DevExpress.ExpressApp.Model;

namespace MainDemo.Module {
    public sealed partial class MainDemoModule : ModuleBase {
        public MainDemoModule() {
            InitializeComponent();
            ModelEditorGroupingHelper.Instance.RegisterNodeGroupPathDelegate(
            typeof(IModelValidationRules), node => DefaultGroupPathCalculator("TargetType.Name", node));
        }
        public string[] DefaultGroupPathCalculator(string propertyName, IModelNode modelNode) {
            string groupName = "";
            object propertyValue = ModelEditorGroupingHelper.Instance.GetPropertyValue(propertyName, modelNode);
            if(propertyValue != null) {
                groupName = propertyValue.ToString();
            }
            return ModelEditorGroupingHelper.Instance.SplitGroupPath(groupName, modelNode);
        }
        //...
    }
}

This is just one example of the Model Editor nodes grouping customizations that you can achieve with the ModelEditorGroupingHelper  API.

I remember our loyal customer Mario Blataric doing magic using this helper for his specific project needs (multi-level grouping of Actions by Controllers and their namespaces/functional blocks). If you have similar needs in your project, feel free to contact our support team so we can help you make your life easier.

11 comments:

  1. Ticket is private ;)

    Thx
    Noxe

    ReplyDelete
  2. Thanks for your feedback, Guys. I've fixed that, sorry.

    ReplyDelete
  3. this one is nice.

    ReplyDelete
  4. Looks like a candidate for functionality "out of the box".

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Ignore my last Q - spotted the answer in the documentation.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete