Name | Surname | Marital status | Age | Employed |
---|---|---|---|---|
Joe | Crosswave | Married | 36 | False |
Merry | Lisel | Widowed | 46 | |
Henry | Crux | Single | 34 | True |
Cody | Jurut | 54 | False | |
Simon | Scranton | Single | 39 | |
Leena | Laurent | Divorced | 24 | False |
Ode | Cosmides | Married | 58 | True |
Diandra | Mizner | Single | 25 | False |
Pete | Cassel | Married | 27 | False |
Nicky | Tremblay | Married | 36 | True |
MvcGrid.Filters.Register(typeof(Int32), "contains", typeof(NumberContainsFilter))
public class NumberContainsFilter : BaseGridFilter
{
public override Expression Apply(Expression expression)
{
if (Values.Count == 0 || Values.Any(String.IsNullOrEmpty))
return null;
return base.Apply(expression);
}
protected override Expression Apply(Expression expression, String value)
{
Expression valueExpression = Expression.Constant(value.ToUpper());
MethodInfo toStringMethod = typeof(Int32).GetMethod("ToString", new Type[0]);
MethodInfo containsMethod = typeof(String).GetMethod("Contains", new[] { typeof(String) });
Expression toString = Expression.Call(expression, toStringMethod);
return Expression.Call(toString, containsMethod, valueExpression);
}
}
var ExtendedNumberFilter = (function (base) {
MvcGridExtends(ExtendedNumberFilter, base);
function ExtendedNumberFilter(column) {
base.call(this, column);
this.methods.unshift('contains');
}
return ExtendedNumberFilter;
})(MvcGridNumberFilter);
new MvcGrid(document.querySelector('.mvc-grid'), {
filters: {
'number': ExtendedNumberFilter
}
});
MvcGrid.prototype.lang.number.contains = 'Contains';