forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSorter.cs
More file actions
169 lines (151 loc) · 5.18 KB
/
DataSorter.cs
File metadata and controls
169 lines (151 loc) · 5.18 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
/********
* @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>
///
/// </summary>
[Meta]
public partial class DataSorter : BaseItem
{
/// <summary>
///
/// </summary>
public DataSorter()
{
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static DataSorter[] From(string value)
{
if (value.IsNotEmpty())
{
return JSON.Deserialize<DataSorter[]>(value, new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver());
}
return new DataSorter[0];
}
/// <summary>
/// The direction to sort by. Defaults to ASC
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(SortDirection.Default)]
[NotifyParentProperty(true)]
[Description("The direction to sort by. Defaults to ASC")]
public SortDirection Direction
{
get
{
return this.State.Get<SortDirection>("Direction", SortDirection.Default);
}
set
{
this.State.Set("Direction", value);
}
}
/// <summary>
/// The property to sort by. Required unless sorterFn is provided
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue("")]
[Description("The property to sort by. Required unless sorterFn is provided")]
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 sorting 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 sorting 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);
}
}
private JFunction sorterFn;
/// <summary>
/// A specific sorter function to execute. Can be passed instead of property
/// Parameters
/// item1 : first data item
/// item2 : second data item
/// </summary>
[ConfigOption(JsonMode.Raw)]
[DefaultValue(null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[Description("A specific sorter function to execute. Can be passed instead of property")]
public virtual JFunction SorterFn
{
get
{
if (this.sorterFn == null)
{
this.sorterFn = new JFunction();
if (!this.DesignMode)
{
this.sorterFn.Args = new string[] { "item1", "item2" };
}
}
return this.sorterFn;
}
}
private JFunction transform;
/// <summary>
/// function that will be run on each value before it is compared in the sorter. The function will receive a single argument, the value.
/// Parameters
/// item : data item
/// </summary>
[ConfigOption(JsonMode.Raw)]
[DefaultValue(null)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[Description(" function that will be run on each value before it is compared in the sorter. The function will receive a single argument, the value.")]
public virtual JFunction Transform
{
get
{
if (this.transform == null)
{
this.transform = new JFunction();
if (!this.DesignMode)
{
this.transform.Args = new string[] { "item" };
}
}
return this.transform;
}
}
}
/// <summary>
///
/// </summary>
public partial class DataSorterCollection : BaseItemCollection<DataSorter> { }
}