1: using System.Collections.Generic;
2: using System.Web.Script.Serialization;
3:
4: namespace FlexiGridTutorial.Models
5: { 6: public class FlexiGridBuilder
7: { 8: public enum Align
9: { 10: left,
11: center,
12: right
13: } ;
14:
15: public class Column
16: { 17: public readonly string display;
18: public readonly string name;
19: public readonly string width;
20: public readonly bool sortable;
21: public readonly Align align;
22: public readonly bool hide;
23:
24: public Column(string display, string name, string width, bool sortable, Align align, bool hide)
25: { 26: this.display = display;
27: this.name = name;
28: this.width = width;
29: this.sortable = sortable;
30: this.align = align;
31: this.hide = hide;
32: }
33: } ;
34:
35: public class Button
36: { 37:
38: }
39:
40: public class SearchItem
41: { 42: public string display;
43: public string name;
44: public bool isdefault;
45:
46: public SearchItem(string display, string name, bool isdefault)
47: { 48: this.display = display;
49: this.name = name;
50: this.isdefault = isdefault;
51: }
52: }
53:
54: public string url;
55: public string dataType;
56: public IList<Column> colModel;
57: public IList<Button> buttons;
58: public IList<SearchItem> searchitems;
59: public string sortname;
60: public string sortorder;
61: public bool usepager;
62: public string title;
63: public bool useRp;
64: public short rp;
65: public bool showTableToggleBtn;
66: public short width;
67: public short height;
68:
69: public FlexiGridBuilder(string param_title)
70: { 71: this.title = param_title;
72: this.url = null;
73: this.dataType = "json";
74:
75: this.usepager = true;
76: this.useRp = true;
77: this.rp = 15;
78: this.showTableToggleBtn = true;
79: this.width = 500;
80: this.height= 200;
81: this.sortorder = "asc";
82:
83: this.colModel = new List<Column>();
84: this.buttons = new List<Button>();
85: this.searchitems = new List<SearchItem>();
86: }
87:
88: public FlexiGridBuilder SetDataUrl(string u)
89: { 90: this.url = u;
91: return this;
92: }
93:
94: public FlexiGridBuilder SetWidth(short w)
95: { 96: this.width = w;
97: return this;
98: }
99:
100: public FlexiGridBuilder SetHeight(short h)
101: { 102: this.height= h;
103: return this;
104: }
105:
106: public FlexiGridBuilder ShowToggleButton(bool bSet)
107: { 108: this.showTableToggleBtn = bSet;
109: return this;
110: }
111:
112: public FlexiGridBuilder UsePager(bool bSet)
113: { 114: this.usepager = bSet;
115: return this;
116: }
117:
118: public FlexiGridBuilder SetDefaultSort(string field, string order)
119: { 120: this.sortname = field;
121: this.sortorder = order;
122: return this;
123: }
124:
125: public FlexiGridBuilder AddColumn(string col_display, string col_name, short col_width, bool col_sortable, Align col_align, bool col_hide)
126: { 127: return AddColumn(col_display, col_name, col_width.ToString(), col_sortable, col_align, col_hide);
128: }
129:
130: public FlexiGridBuilder AddColumn(string col_display, string col_name, string col_width, bool col_sortable, Align col_align, bool col_hide)
131: { 132: colModel.Add(new Column(col_display, col_name, col_width, col_sortable, col_align, col_hide));
133: if (this.sortname == null)
134: this.sortname = col_name;
135:
136: return this;
137: }
138:
139: public FlexiGridBuilder AddColumn(string col_display, string col_name, string col_width, bool col_sortable, Align col_align)
140: { 141: return AddColumn(col_display, col_name, col_width, col_sortable, col_align, false);
142: }
143:
144: public FlexiGridBuilder AddColumn(string col_display, string col_name, short col_width, bool col_sortable, Align col_align)
145: { 146: return AddColumn(col_display, col_name, col_width.ToString(), col_sortable, col_align, false);
147: }
148:
149: public FlexiGridBuilder AddSearchItem(string si_display, string si_name, bool si_isdefault)
150: { 151: searchitems.Add(new SearchItem(si_display, si_name, si_isdefault));
152: return this;
153: }
154:
155: public string ToJson()
156: { 157: var serializer = new JavaScriptSerializer();
158: return serializer.Serialize(this);
159: }
160:
161: public string Create(string id)
162: { 163: return string.Format("$(\"#{0}\").flexigrid({1});", id, ToJson()); 164: }
165: }
166: }
167: