-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathFilterDef.cs
55 lines (49 loc) · 1.48 KB
/
FilterDef.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Mvc.JQuery.DataTables
{
public class FilterDef : Hashtable
{
internal object[] values { set { this["values"] = value; } }
internal string type { set { this["type"] = value; } }
public FilterDef(Type t)
{
SetDefaultValuesAccordingToColumnType(t);
}
private static List<Type> DateTypes = new List<Type> { typeof(DateTime), typeof(DateTime?), typeof(DateTimeOffset), typeof(DateTimeOffset?) };
private void SetDefaultValuesAccordingToColumnType(Type t)
{
if (t==null)
{
this.Remove("type");
}
else if (DateTypes.Contains(t))
{
type = "date-range";
}
else if (t == typeof (bool))
{
type = "select";
values = new object[] {"True", "False"};
}
else if (t == typeof (bool?))
{
type = "select";
values = new object[] {"True", "False", "null"};
}
else if (t.GetTypeInfo().IsEnum)
{
type = "checkbox";
//values = Enum.GetNames(t).Cast<object>().ToArray();
values = t.EnumValLabPairs();
}
else
{
type = "text";
}
}
}
}