forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataFilter.cs
More file actions
196 lines (179 loc) · 6.22 KB
/
DataFilter.cs
File metadata and controls
196 lines (179 loc) · 6.22 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/********
* @version : 2.1.1 - Ext.NET Pro License
* @author : Ext.NET, Inc. http://www.ext.net/
* @date : 2012-12-10
* @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license : See license.txt and http://www.ext.net/license/.
********/
using System.ComponentModel;
using System.Web.UI;
using Ext.Net.Utilities;
namespace Ext.Net
{
/// <summary>
/// Represents a filter that can be applied to a MixedCollection. Can either simply filter on a property/value pair or pass in a filter function with custom logic. Filters are always used in the context of MixedCollections, though Stores frequently create them when filtering and searching on their records.
/// </summary>
[Meta]
public partial class DataFilter : BaseItem
{
/// <summary>
///
/// </summary>
public DataFilter()
{
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static DataFilter[] From(string value)
{
if (value.IsNotEmpty())
{
return JSON.Deserialize<DataFilter[]>(value, new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver());
}
return new DataFilter[0];
}
/// <summary>
/// True to allow any match - no regex start/end line anchors will be added. Defaults to false
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(false)]
[Description("True to allow any match - no regex start/end line anchors will be added. Defaults to false")]
public virtual bool AnyMatch
{
get
{
return this.State.Get<bool>("AnyMatch", false);
}
set
{
this.State.Set("AnyMatch", value);
}
}
/// <summary>
/// True to make the regex case sensitive (adds 'i' switch to regex). Defaults to false.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(false)]
[Description("True to make the regex case sensitive (adds 'i' switch to regex). Defaults to false.")]
public virtual bool CaseSensitive
{
get
{
return this.State.Get<bool>("CaseSensitive", false);
}
set
{
this.State.Set("CaseSensitive", value);
}
}
/// <summary>
/// True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(false)]
[Description("True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.")]
public virtual bool ExactMatch
{
get
{
return this.State.Get<bool>("ExactMatch", false);
}
set
{
this.State.Set("ExactMatch", value);
}
}
private JFunction filterFn;
/// <summary>
/// A custom filter function which is passed each item in the Ext.util.MixedCollection in turn. Should return true to accept each item or false to reject it
/// Parameters
/// item : data item
/// </summary>
[ConfigOption(JsonMode.Raw)]
[DefaultValue(null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[Description("A custom filter function which is passed each item in the Ext.util.MixedCollection in turn. Should return true to accept each item or false to reject it")]
public virtual JFunction FilterFn
{
get
{
if (this.filterFn == null)
{
this.filterFn = new JFunction();
if (!this.DesignMode)
{
this.filterFn.Args = new string[] { "item" };
}
}
return this.filterFn;
}
}
/// <summary>
/// The property to filter on. Required unless a filter is passed
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue("")]
[Description("The property to filter on. Required unless a filter is passed")]
public virtual string Property
{
get
{
return this.State.Get<string>("Property", "");
}
set
{
this.State.Set("Property", value);
}
}
/// <summary>
/// Optional root property. This is mostly useful when filtering a Store, in which case we set the root to 'data' to make the filter pull the property out of the data object of each item
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue("")]
[Description("Optional root property. This is mostly useful when filtering a Store, in which case we set the root to 'data' to make the filter pull the property out of the data object of each item")]
public virtual string Root
{
get
{
return this.State.Get<string>("Root", "");
}
set
{
this.State.Set("Root", value);
}
}
/// <summary>
/// Filter value
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(null)]
[Description("Filter value")]
public virtual string Value
{
get
{
return (string)this.ViewState["Value"];
}
set
{
this.State.Set("Value", value);
}
}
}
/// <summary>
///
/// </summary>
public partial class DataFilterCollection : BaseItemCollection<DataFilter>
{
}
}