Example of Lock Group/Rule in ASP.NET MVC Query Builder Control
This sample demonstrates the lock support of the Query Builder control. Click the lock button to lock 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 = "lockQb",
ShowButtons = new UiQueryShowButtons { LockRule = true, LockGroup = 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 = "Country", Label = "Country", Values = new List<object> { "USA", "UK", "Ireland" } },
new UiQueryBuilderColumn { Field = "Salary", Label = "Salary", Type = UiQueryColumnType.Number }
},
Rule = (UiRuleGroup)ViewData["rule"]
})
@Html.UiQueryBuilder(new UiQueryBuilderOptions
{
Id = "lockQb",
ShowButtons = new UiQueryShowButtons { LockRule = true, LockGroup = 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 = "Country", Label = "Country", Values = new List<object> { "USA", "UK", "Ireland" } },
new UiQueryBuilderColumn { Field = "Salary", Label = "Salary", Type = UiQueryColumnType.Number }
},
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/LockGroupRule.cshtml; it draws what ViewData holds.
public ActionResult LockGroupRule()
{
UiRuleGroup rule = new UiRuleGroup
{
Condition = "and",
Rules =
{
new UiRule { Field = "Country", Operator = "equal", Value = "USA", IsLocked = true },
new UiRule { Field = "FirstName", Operator = "startswith", Value = "N" },
new UiRule
{
Condition = "or",
IsLocked = true,
Rules = new List<UiRule>
{
new UiRule { Field = "Salary", Operator = "greaterthan", Value = 50000 },
new UiRule { Field = "EmployeeId", Operator = "lessthan", Value = 5 }
}
}
}
};
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 lock options are available for rules as well as groups. When a rule is locked, the field, operator, and value will be disabled. When a group is locked, all the elements within the group will be disabled.
In mobile mode, the control is shown vertically.