-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataGrid.cs
111 lines (90 loc) · 3.45 KB
/
DataGrid.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Dojo.Net
{
public class DataGrid : DojoControl
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Attributes["plugins"] = "{pagination: {sizeSwitch: false, gotoButton: true, position: 'top'}}";
Require("dojox.grid.enhanced.plugins.Pagination");
Page.ClientScript.RegisterClientScriptBlock(GetType(), "Css", String.Format(@"<link rel=""stylesheet"" type=""text/css"" href=""{0}/dojo.axd/Scripts/dojox/grid/enhanced/resources/EnhancedGrid.css""/>
", Page.Request.ApplicationPath));
Page.ClientScript.RegisterClientScriptBlock(GetType(), "ThemeCss", String.Format(@"<link rel=""stylesheet"" type=""text/css"" href=""{0}/dojo.axd/Scripts/dojox/grid/enhanced/resources/{1}/EnhancedGrid.css""/>
", Page.Request.ApplicationPath, ResourceManager.ThemeName ?? ResourceManager.Theme.ToString("G").ToLower()));
}
protected override string DojoType
{
get
{
return "dojox.grid.EnhancedGrid";
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
StringBuilder storeJavaScript = new StringBuilder(ID + "Store = new ");
if (Store[0] is JsonStore)
{
JsonStore store = (JsonStore) Store[0];
storeJavaScript.Append("dojox.data.JsonRestStore(");
Require("dojox.data.JsonRestStore");
if (String.IsNullOrEmpty(store.ServiceObject))
storeJavaScript.AppendFormat(@"{{
target: ""{0}"",
idAttribute: ""{1}""
}});", store.Target, store.IdAttribute);
else
storeJavaScript.AppendFormat(@"{{
service: {0}
}});", store.ServiceObject);
}
Page.ClientScript.RegisterClientScriptBlock(GetType(), ID + "StoreRegistration", storeJavaScript.ToString(), true);
Attributes["store"] = ID + "Store";
}
protected override void RenderContents(HtmlTextWriter writer)
{
if (Columns == null)
return;
writer.RenderBeginTag("thead");
writer.RenderBeginTag("tr");
foreach (Column column in Columns)
{
writer.AddAttribute("field", column.DataField);
if (column.Width.Value > 0)
writer.AddAttribute("width", column.Width.ToString());
if (!String.IsNullOrEmpty(column.Formatter))
writer.AddAttribute("formatter", column.Formatter);
writer.RenderBeginTag("th");
writer.Write(column.HeaderText);
writer.RenderEndTag();
}
writer.RenderEndTag();
writer.RenderEndTag();
}
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Table;
}
}
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<Column> Columns
{
get;
set;
}
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<Store> Store
{
get;
set;
}
}
}