Example of Clone Group/Rule in ASP.NET MVC Query Builder Control
This sample demonstrates the clone support of the Query Builder control. Click the clone button to clone the group or rule.
@* The editor's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiQueryBuilder(new UiQueryBuilderOptions
{
Id = "cloneQb",
ShowButtons = new UiQueryShowButtons { CloneRule = true, CloneGroup = true },
Columns = new List<UiQueryBuilderColumn>
{
new UiQueryBuilderColumn { Field = "EmployeeId", Label = "Employee ID", Type = UiQueryColumnType.Number },
new UiQueryBuilderColumn { Field = "FirstName", Label = "First Name" },
new UiQueryBuilderColumn { Field = "City", Label = "City" },
new UiQueryBuilderColumn { Field = "HireDate", Label = "Hire Date", Type = UiQueryColumnType.Date }
},
Rule = (UiRuleGroup)ViewData["rule"]
})
@Html.UiQueryBuilder(new UiQueryBuilderOptions
{
Id = "cloneQb",
ShowButtons = new UiQueryShowButtons { CloneRule = true, CloneGroup = true },
Columns = new List<UiQueryBuilderColumn>
{
new UiQueryBuilderColumn { Field = "EmployeeId", Label = "Employee ID", Type = UiQueryColumnType.Number },
new UiQueryBuilderColumn { Field = "FirstName", Label = "First Name" },
new UiQueryBuilderColumn { Field = "City", Label = "City" },
new UiQueryBuilderColumn { Field = "HireDate", Label = "Hire Date", Type = UiQueryColumnType.Date }
},
Rule = (UiRuleGroup)ViewData["rule"]
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class QueryBuilderController : Controller
{
// The page is Views/QueryBuilder/CloneGroupRule.cshtml; it draws what ViewData holds.
public ActionResult CloneGroupRule()
{
UiRuleGroup rule = new UiRuleGroup
{
Condition = "and",
Rules =
{
new UiRule { Field = "City", Operator = "equal", Value = "London" },
new UiRule
{
Condition = "or",
Rules = new List<UiRule>
{
new UiRule { Field = "FirstName", Operator = "startswith", Value = "R" },
new UiRule { Field = "HireDate", Operator = "lessthan", Value = new DateTime(2023, 6, 1) }
}
}
}
};
ViewData["rule"] = rule;
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Clone options will create an exact replica of a rule or group next to the original.
In mobile mode, the control is shown vertically.