Name | Surname | Marital status | Age | Employed |
---|---|---|---|---|
Joe | Crosswave | Married | 32 | False |
Merry | Lisel | Widowed | 42 | |
Henry | Crux | Single | 30 | True |
Cody | Jurut | 50 | False | |
Simon | Scranton | Single | 35 | |
Leena | Laurent | Divorced | 20 | False |
Ode | Cosmides | Married | 54 | True |
Diandra | Mizner | Single | 21 | False |
Pete | Cassel | Married | 23 | False |
Nicky | Tremblay | Married | 32 | True |
Mary | Cassel | Married | 25 | True |
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcGrid(filters =>
filters.Register(typeof(Int32), "contains", typeof(NumberContainsFilter)));
}
public class NumberContainsFilter : AGridFilter
{
public override Expression? Apply(Expression expression, CultureInfo culture)
{
if (Values.Length == 0 || Values.Any(String.IsNullOrEmpty))
return null;
return base.Apply(expression, culture);
}
protected override Expression? Apply(Expression expression, String? value, CultureInfo culture)
{
Expression valueExpression = Expression.Constant(value?.ToUpper());
MethodInfo toStringMethod = typeof(Int32).GetMethod(nameof(Int32.ToString), new Type[0])!;
MethodInfo containsMethod = typeof(String).GetMethod(nameof(String.Contains), new[] { typeof(String) })!;
Expression toString = Expression.Call(expression, toStringMethod);
// (x) => x.ToString().Contains(value)
return Expression.Call(toString, containsMethod, valueExpression);
}
}
class ExtendedNumberFilter extends MvcGridNumberFilter {
constructor (column) {
super(column);
this.methods.unshift("contains");
}
}
new MvcGrid(document.querySelector(".mvc-grid"), {
filters: {
"number": ExtendedNumberFilter
}
});
MvcGrid.lang.number.contains = "Contains";