3 Partial Class SimpleGrid
\r
4 Inherits System.Web.UI.UserControl
\r
6 Private _gridHeading As ITemplate = Nothing
\r
7 Protected HdgContainer As New GridContainer()
\r
9 Public columns as New ArrayList()
\r
10 Public gridVar as String
\r
11 Public optionsVar as String ' name of grid options js var
\r
12 Public FilterLocation as Integer = -2
\r
13 Public FilterAllToken as String
\r
14 Public FilterBoxMaxLen as Integer = -1
\r
15 Public FilterAnchorLeft as Boolean = false ' when matching text box values, should they match beginning of string (true) or anywhere in string (false)?
16 Public UsingMinRico as Boolean = True ' using minified version of Rico?
\r
17 Public defaultWidth as Integer = -1 ' if -1, then use unformatted column width, otherwise this is the default width in pixels
\r
18 Public menuEvent as String
\r
19 public rows as New ArrayList()
\r
20 public FrozenCols as Integer
\r
21 private LastRow,LastHeadingRow,ResizeRowIdx
\r
26 gridVar=Me.UniqueId & "['grid']"
\r
27 optionsVar=Me.UniqueId & "['options']"
\r
29 If Not (_gridHeading Is Nothing) Then
\r
30 _gridHeading.InstantiateIn(HdgContainer)
\r
31 For Each ctrl As Control In HdgContainer.Controls
\r
32 If TypeOf(ctrl) is GridColumn then
\r
40 Public Class HeadingCellClass
\r
41 Public content As String, span As Integer
\r
43 Public Sub New(Optional contentParm As String = "", Optional spanParm As Integer = 1)
\r
49 class SimpleGridCell
\r
50 public content as String
\r
51 private attr As New Hashtable()
\r
53 Public Function HeadingCell() as object
\r
54 Dim s as String, span as Integer
\r
57 If attr.contains("colspan") Then
\r
58 span=CInt(attr("colspan"))
\r
59 s &= " colspan='" & span & "'"
\r
61 dim content as String=s & "><div class='ricoLG_col'>" & DataCell("") & "</div></td>"
\r
62 dim result() as object = {content,span}
\r
63 HeadingCell = result
\r
66 Public Function DataCell(rowclass as String) as String
\r
67 dim s as String, k as String
\r
69 attr("class")=trim("ricoLG_cell " & attr("class") & " " & rowclass)
\r
70 for each k in attr.keys
\r
71 If k<>"colspan" Then s=s & " " & k & "='" & attr(k) & "'"
\r
73 s=s & ">" & content & "</div>"
\r
77 Public Function HtmlCell()
\r
78 dim s as String="", k as String
\r
79 for each k in attr.keys
\r
80 s &= " " & k & "='" & attr(k) & "'"
\r
82 HtmlCell="<td" & s & ">" & content & "</td>"
\r
85 Public Sub SetAttr(name as String, value as String)
\r
92 public cells as New ArrayList()
\r
93 private attr As New Hashtable()
\r
94 private CurrentCell as SimpleGridCell
\r
96 Public Sub AddCell(ByVal content as String)
\r
97 CurrentCell=new SimpleGridCell()
\r
98 cells.Add(CurrentCell)
\r
99 CurrentCell.content=content
\r
102 Public Function HeadingRow(ByVal c1 as Integer, ByVal c2 as Integer) as String
\r
104 dim cellidx as Integer=0
\r
105 dim colidx as Integer=0
\r
106 while colidx < c1 and cellidx < cells.count
\r
107 a=cells(cellidx).HeadingCell()
\r
111 while (colidx <= c2 or c2=-1) and cellidx < cells.count
\r
112 a=cells(cellidx).HeadingCell()
\r
120 Public Function HeadingClass()
\r
121 HeadingClass=trim("ricoLG_hdg " & attr("class"))
\r
124 Public Function CellCount()
\r
125 CellCount=cells.count
\r
128 Public Function GetRowAttr(ByVal name)
\r
129 GetRowAttr=attr(name)
\r
132 Public Sub SetRowAttr(ByVal name, ByVal value)
\r
136 Public Sub SetCellAttr(ByVal name, ByVal value)
\r
137 CurrentCell.SetAttr(name,value)
\r
142 Public Function AddHeadingRow(ResizeRowFlag as Boolean)
\r
143 LastHeadingRow=AddDataRow()
\r
144 if ResizeRowFlag then ResizeRowIdx=LastHeadingRow
\r
145 AddHeadingRow=LastHeadingRow
\r
148 Public Function AddDataRow()
\r
149 rows.Add(new SimpleGridRow())
\r
150 LastRow=rows.count-1
\r
154 Public Function HeadingRowCount()
\r
155 if IsNothing(LastHeadingRow) then
\r
158 HeadingRowCount=LastHeadingRow+1
\r
162 Public Function DataRowCount()
\r
163 if IsNothing(LastRow) then
\r
166 DataRowCount=LastRow+1-HeadingRowCount()
\r
170 ' returns # of cells in the current row
\r
171 Public Function CellCount()
\r
172 CellCount=rows(LastRow).CellCount
\r
175 Public Sub AddCell(ByVal content as String)
\r
176 rows(LastRow).AddCell(content)
\r
179 Public Sub AddCellToRow(ByVal RowIdx as Integer, ByVal content as String)
\r
184 Public Sub SetRowAttr(ByVal name as String, ByVal value as String)
\r
185 rows(LastRow).SetRowAttr(name,value)
\r
188 Public Sub SetCellAttr(ByVal name as String, ByVal value as String)
\r
189 rows(LastRow).SetCellAttr(name,value)
\r
192 Private Function RenderColumns(writer as HTMLTextWriter, c1 as Integer, c2 as Integer)
\r
193 dim r as Integer, c as Integer
\r
195 writer.Write("<td><div class='ricoLG_col'>")
\r
196 for r=LastHeadingRow+1 to rows.count-1
\r
197 writer.Write(rows(r).cells(c).DataCell(rows(r).GetRowAttr("class")))
\r
199 writer.WriteLine("</div></td>")
\r
203 <TemplateContainer(GetType(GridContainer))> _
\r
204 Public Property GridColumns() As ITemplate
\r
206 Return _gridHeading
\r
209 _gridHeading = value
\r
213 Protected Overrides Sub Render(writer as HTMLTextWriter)
\r
214 dim colcnt as Integer, r as Integer, c as Integer
\r
215 if IsNothing(ResizeRowIdx) then exit sub
\r
216 colcnt=rows(ResizeRowIdx).CellCount
\r
218 writer.WriteLine("<script type='text/javascript'>")
\r
219 if not UsingMinRico then writer.WriteLine("Rico.loadModule('SimpleGrid');")
\r
220 writer.WriteLine("var " & Me.UniqueId & " = {};")
\r
221 writer.WriteLine("Rico.onLoad( function() {")
\r
222 writer.WriteLine(" " & optionsVar & " = {")
\r
223 if FilterLocation >= -1 then writer.WriteLine(" FilterLocation: " & FilterLocation & ",")
\r
224 if not IsNothing(FilterAllToken) then writer.WriteLine(" FilterAllToken: '" & FilterAllToken & "',")
\r
225 if FilterBoxMaxLen >= 0 then writer.WriteLine(" FilterBoxMaxLen: " & FilterBoxMaxLen & ",")
\r
226 if FilterAnchorLeft then writer.WriteLine(" FilterAnchorLeft: " & lcase(FilterAnchorLeft) & ",")
\r
227 if defaultWidth > 0 then writer.WriteLine(" defaultWidth: " & defaultWidth & ",")
\r
228 if not IsNothing(menuEvent) then writer.WriteLine(" menuEvent: '" & menuEvent & "',")
\r
229 writer.WriteLine(" columnSpecs: [")
\r
230 for c=0 to columns.count-1
\r
231 if c > 0 then writer.WriteLine(",")
\r
232 writer.Write(CType(columns(c),GridColumn).script)
\r
234 writer.WriteLine(vbCrLf & " ]")
\r
235 writer.WriteLine(" };")
\r
236 writer.WriteLine(" " & gridVar & "=new Rico.SimpleGrid('" & Me.UniqueId & "', " & optionsVar & ");")
\r
237 writer.WriteLine(" if(typeof " & Me.UniqueId & "_InitComplete=='function') " & Me.UniqueId & "_InitComplete();" & vbCrLf)
\r
238 writer.WriteLine("});")
\r
239 writer.WriteLine("</script>")
\r
241 writer.Write("<div id='" & Me.UniqueId & "_outerDiv'>")
\r
243 '-------------------
\r
245 '-------------------
\r
246 writer.WriteLine("<div id='" & Me.UniqueId & "_frozenTabsDiv'>")
\r
249 writer.WriteLine("<table id='" & Me.UniqueId & "_tab0h' class='ricoLG_table ricoLG_top ricoLG_left' cellspacing='0' cellpadding='0'><thead>")
\r
250 for r=0 to LastHeadingRow
\r
251 writer.Write("<tr class='" & rows(r).HeadingClass() & "'")
\r
252 if r=ResizeRowIdx then writer.Write(" id='" & Me.UniqueId & "_tab0h_main'")
\r
253 writer.WriteLine(">")
\r
254 writer.Write(rows(r).HeadingRow(0,FrozenCols-1))
\r
255 writer.Write("</tr>")
\r
257 writer.WriteLine("</thead></table>")
\r
260 writer.Write("<table id='" & Me.UniqueId & "_tab0' class='ricoLG_table ricoLG_bottom ricoLG_left' cellspacing='0' cellpadding='0'>")
\r
261 writer.WriteLine("<tr>")
\r
262 RenderColumns(writer,0,FrozenCols-1)
\r
263 writer.Write("</tr>")
\r
264 writer.WriteLine("</table>")
\r
266 writer.WriteLine("</div>")
\r
269 '-------------------
\r
270 ' scrolling columns
\r
271 '-------------------
\r
274 writer.Write("<div id='" & Me.UniqueId & "_innerDiv'>")
\r
275 writer.Write("<div id='" & Me.UniqueId & "_scrollTabsDiv'>")
\r
276 writer.WriteLine("<table id='" & Me.UniqueId & "_tab1h' class='ricoLG_table ricoLG_top ricoLG_right' cellspacing='0' cellpadding='0'><thead>")
\r
277 for r=0 to LastHeadingRow
\r
278 writer.Write("<tr class='" & rows(r).HeadingClass & "'")
\r
279 if r=ResizeRowIdx then writer.Write(" id='" & Me.UniqueId & "_tab1h_main'")
\r
281 writer.Write(rows(r).HeadingRow(FrozenCols,-1))
\r
282 writer.Write("</tr>")
\r
284 writer.Write("</thead></table>")
\r
285 writer.Write("</div>")
\r
286 writer.WriteLine("</div>")
\r
289 writer.Write("<div id='" & Me.UniqueId & "_scrollDiv'>")
\r
290 writer.Write("<table id='" & Me.UniqueId & "_tab1' class='ricoLG_table ricoLG_bottom ricoLG_right' cellspacing='0' cellpadding='0'>")
\r
291 writer.WriteLine("<tr>")
\r
292 RenderColumns(writer,FrozenCols,colcnt-1)
\r
293 writer.Write("</tr>")
\r
294 writer.Write("</table>")
\r
295 writer.Write("</div>")
\r
297 writer.WriteLine("</div>")
\r
300 ' Response.Buffer must be true
\r
301 Public Sub RenderExcel(fileName)
\r
302 Dim r as Integer, c as Integer
\r
303 Dim sw As New System.IO.StringWriter
\r
305 HttpContext.Current.Response.Clear()
\r
306 if fileName<>"" then HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & fileName)
\r
307 HttpContext.Current.Response.ContentType = "application/ms-excel"
\r
309 sw.WriteLine("<table>")
\r
310 for r=0 to rows.count-1
\r
311 sw.WriteLine("<tr>")
\r
312 for c=0 to rows(r).CellCount()-1
\r
313 sw.Write(rows(r).cells(c).HtmlCell())
\r
315 sw.WriteLine("</tr>")
\r
317 sw.WriteLine("</table>")
\r
318 HttpContext.Current.Response.Write(sw.ToString)
\r
319 HttpContext.Current.Response.End()
\r
322 ' Response.Buffer must be true
\r
323 Public Sub RenderDelimited(fileName,delim,SubstituteChar)
\r
324 Dim r as Integer, c as Integer
\r
325 Dim sw As New System.IO.StringWriter
\r
327 HttpContext.Current.Response.Clear()
\r
328 if fileName<>"" then HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & fileName)
\r
329 HttpContext.Current.Response.ContentType = "text/csv"
\r
331 for r=0 to rows.count-1
\r
332 for c=0 to rows(r).CellCount()-1
\r
333 if c > 0 then sw.Write(delim)
\r
334 sw.Write(replace(rows(r).cells(c).content,delim,SubstituteChar))
\r
338 HttpContext.Current.Response.Write(sw.ToString)
\r
339 HttpContext.Current.Response.End()
\r
342 Public Class GridContainer
\r
344 Implements INamingContainer
\r