QueryAttribute and FilterLayoutAttribute
QueryAttribute
namespace: MvcControlsToolkit.Core.DataAnnotations
The QueryAttribute enables queries (grouping, sorting, filtering) on a ViewModel property, and specifies which query operations are allowed. Allowed operations
are described by the QueryOptions flag enum:
[Flags] public enum QueryOptions: uint { None = 0, Equal = 1, NotEqual = 2, LessThan = 4, LessThanOrEqual = 8, GreaterThan = 16, GreaterThanOrEqual = 32, StartsWith = 64, EndsWith = 128, Contains = 256, IsContainedIn = 512, Search =1024, OrderBy=2048, GroupBy=4096, AllFilters = 1023, All = 8191}
More specifically, the QueryAttribute has two QueryOptions properties: Allow, and Deny.
It allows all operations contained in Allow and not contained in Deny.
These properties have the following defaults:
Allow = QueryOptions.Equal | QueryOptions.LessThan | QueryOptions.LessThanOrEqual | QueryOptions.GreaterThan | QueryOptions.GreaterThanOrEqual | QueryOptions.NotEqual | QueryOptions.StartsWith | QueryOptions.EndsWith | QueryOptions.IsContainedIn | QueryOptions.Contains | QueryOptions.OrderBy | QueryOptions.GroupBy ; Deny = QueryOptions.IsContainedIn | QueryOptions.Contains | QueryOptions.Search;
All methods that verifies permissions automatically subtract all operations that make no sense for the property type (for instance, StartsWith for a not string)
The developer may customize allowed operations either by replacing the values of
Allow and/or Deny, or by using the Add and Remove
properties. More specifically all bit flags assigned to the Add property are
added to the bit flags already contained in Allow, while all bit flags assigned to Remove
are added to the ones already contained in Deny.
Below some examples:
-
[Query(Deny = QueryOptions.None)] string AString { get; set; }
-
[Query(Allow = QueryOptions.StartsWith)] string AString { get; set; }
-
[Query(Remove = QueryOptions.GroupBy)] string AString { get; set; }
In a templated control the operations stated in a QueryAttribute may be further constrained
by using the column query-constraints attribute
FilterLayoutAttribute
namespace: MvcControlsToolkit.Core.DataAnnotations
The FilterLayoutAttribute specifies how many filter conditions to render for a property
in a filter window, and for each condition it further constrains the allowed filter operations.
All constraints are specified through a QueryOptions params array. The number of conditions
rendered corresponds to the length of the array. If no FilterLayoutAttribute is provided, or if
the lenght of the QueryOptions array is 0, a single filter condition is rendered.
[DataType(DataType.Date)] [Query] [FilterLayout(QueryOptions.GreaterThan, QueryOptions.LessThan)] public DateTime? ADate { get; set; }
With the above settings two filter conditions are rendered, that together specifies a date interval.
In a templated control the setting of a FilterLayoutAttribute may be completely overriden
by using the column filter-clauses attribute