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 = False ' 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 allowColResize as Boolean = True
\r
19 Public menuEvent as String
\r
20 public rows as New ArrayList()
\r
21 public FrozenCols as Integer
\r
22 private LastRow,LastHeadingRow,ResizeRowIdx
\r
27 gridVar=Me.UniqueId & "['grid']"
\r
28 optionsVar=Me.UniqueId & "['options']"
\r
30 If Not (_gridHeading Is Nothing) Then
\r
31 _gridHeading.InstantiateIn(HdgContainer)
\r
32 For Each ctrl As Control In HdgContainer.Controls
\r
33 If TypeOf(ctrl) is GridColumn then
\r
41 Public Class HeadingCellClass
\r
42 Public content As String, span As Integer
\r
44 Public Sub New(Optional contentParm As String = "", Optional spanParm As Integer = 1)
\r
50 class SimpleGridCell
\r
51 public content as String
\r
52 private attr As New Hashtable()
\r
54 Public Function HeadingCell() as object
\r
55 Dim s as String, span as Integer
\r
58 If attr.contains("colspan") Then
\r
59 span=CInt(attr("colspan"))
\r
60 s &= " colspan='" & span & "'"
\r
62 dim content as String=s & "><div class='ricoLG_col'>" & DataCell("") & "</div></td>"
\r
63 dim result() as object = {content,span}
\r
64 HeadingCell = result
\r
67 Public Function DataCell(rowclass as String) as String
\r
68 dim s as String, k as String
\r
70 attr("class")=trim("ricoLG_cell " & attr("class") & " " & rowclass)
\r
71 for each k in attr.keys
\r
72 If k<>"colspan" Then s=s & " " & k & "='" & attr(k) & "'"
\r
74 s=s & ">" & content & "</div>"
\r
78 Public Function HtmlCell()
\r
79 dim s as String="", k as String
\r
80 for each k in attr.keys
\r
81 s &= " " & k & "='" & attr(k) & "'"
\r
83 HtmlCell="<td" & s & ">" & content & "</td>"
\r
86 Public Sub SetAttr(name as String, value as String)
\r
93 public cells as New ArrayList()
\r
94 private attr As New Hashtable()
\r
95 private CurrentCell as SimpleGridCell
\r
97 Public Sub AddCell(ByVal content as String)
\r
98 CurrentCell=new SimpleGridCell()
\r
99 cells.Add(CurrentCell)
\r
100 CurrentCell.content=content
\r
103 Public Function HeadingRow(ByVal c1 as Integer, ByVal c2 as Integer) as String
\r
105 dim cellidx as Integer=0
\r
106 dim colidx as Integer=0
\r
107 while colidx < c1 and cellidx < cells.count
\r
108 a=cells(cellidx).HeadingCell()
\r
112 while (colidx <= c2 or c2=-1) and cellidx < cells.count
\r
113 a=cells(cellidx).HeadingCell()
\r
121 Public Function HeadingClass()
\r
122 HeadingClass=trim("ricoLG_hdg " & attr("class"))
\r
125 Public Function CellCount()
\r
126 CellCount=cells.count
\r
129 Public Function GetRowAttr(ByVal name)
\r
130 GetRowAttr=attr(name)
\r
133 Public Sub SetRowAttr(ByVal name, ByVal value)
\r
137 Public Sub SetCellAttr(ByVal name, ByVal value)
\r
138 CurrentCell.SetAttr(name,value)
\r
143 Public Function AddHeadingRow(ResizeRowFlag as Boolean)
\r
144 LastHeadingRow=AddDataRow()
\r
145 if ResizeRowFlag then ResizeRowIdx=LastHeadingRow
\r
146 AddHeadingRow=LastHeadingRow
\r
149 Public Function AddDataRow()
\r
150 rows.Add(new SimpleGridRow())
\r
151 LastRow=rows.count-1
\r
155 Public Function HeadingRowCount()
\r
156 if IsNothing(LastHeadingRow) then
\r
159 HeadingRowCount=LastHeadingRow+1
\r
163 Public Function DataRowCount()
\r
164 if IsNothing(LastRow) then
\r
167 DataRowCount=LastRow+1-HeadingRowCount()
\r
171 ' returns # of cells in the current row
\r
172 Public Function CellCount()
\r
173 CellCount=rows(LastRow).CellCount
\r
176 Public Sub AddCell(ByVal content as String)
\r
177 rows(LastRow).AddCell(content)
\r
180 Public Sub AddCellToRow(ByVal RowIdx as Integer, ByVal content as String)
\r
185 Public Sub SetRowAttr(ByVal name as String, ByVal value as String)
\r
186 rows(LastRow).SetRowAttr(name,value)
\r
189 Public Sub SetCellAttr(ByVal name as String, ByVal value as String)
\r
190 rows(LastRow).SetCellAttr(name,value)
\r
193 Private Sub RenderColumns(writer as HTMLTextWriter, c1 as Integer, c2 as Integer)
\r
194 dim r as Integer, c as Integer
\r
196 writer.Write("<td><div class='ricoLG_col'>")
\r
197 for r=LastHeadingRow+1 to rows.count-1
\r
198 writer.Write(rows(r).cells(c).DataCell(rows(r).GetRowAttr("class")))
\r
200 writer.WriteLine("</div></td>")
\r
204 <TemplateContainer(GetType(GridContainer))> _
\r
205 Public Property GridColumns() As ITemplate
\r
207 Return _gridHeading
\r
210 _gridHeading = value
\r
214 ' returns true if there is a valid heading
\r
215 Private Sub CheckHeading()
\r
216 if not IsNothing(ResizeRowIdx) then exit sub
\r
217 rows.Insert(0, new SimpleGridRow())
\r
221 for c=0 to columns.count-1
\r
222 rows(0).AddCell( CType(columns(c),GridColumn).heading )
\r
226 Private function FmtBool(b)
\r
227 if b then FmtBool="true" else FmtBool="false"
\r
230 Protected Overrides Sub Render(writer as HTMLTextWriter)
\r
231 dim colcnt as Integer, r as Integer, c as Integer
\r
233 colcnt=rows(ResizeRowIdx).CellCount
\r
235 writer.WriteLine("<script type='text/javascript'>")
\r
236 if not UsingMinRico then writer.WriteLine("Rico.loadModule('SimpleGrid');")
\r
237 writer.WriteLine("var " & Me.UniqueId & " = {};")
\r
238 writer.WriteLine("Rico.onLoad( function() {")
\r
239 writer.WriteLine(" " & optionsVar & " = {")
\r
240 if FilterLocation >= -1 then writer.WriteLine(" FilterLocation: " & FilterLocation & ",")
\r
241 if not IsNothing(FilterAllToken) then writer.WriteLine(" FilterAllToken: '" & FilterAllToken & "',")
\r
242 if FilterBoxMaxLen >= 0 then writer.WriteLine(" FilterBoxMaxLen: " & FilterBoxMaxLen & ",")
\r
243 if FilterAnchorLeft then writer.WriteLine(" FilterAnchorLeft: " & lcase(FilterAnchorLeft) & ",")
\r
244 if defaultWidth > 0 then writer.WriteLine(" defaultWidth: " & defaultWidth & ",")
\r
245 if not IsNothing(menuEvent) then writer.WriteLine(" menuEvent: '" & menuEvent & "',")
\r
246 writer.WriteLine(" allowColResize: " & FmtBool(allowColResize) & "," & vbCrLf)
\r
247 writer.WriteLine(" columnSpecs: [")
\r
248 for c=0 to columns.count-1
\r
249 if c > 0 then writer.WriteLine(",")
\r
250 writer.Write(CType(columns(c),GridColumn).script)
\r
252 writer.WriteLine(vbCrLf & " ]")
\r
253 writer.WriteLine(" };")
\r
254 writer.WriteLine(" " & gridVar & "=new Rico.SimpleGrid('" & Me.UniqueId & "', " & optionsVar & ");")
\r
255 writer.WriteLine(" if(typeof " & Me.UniqueId & "_InitComplete=='function') " & Me.UniqueId & "_InitComplete();" & vbCrLf)
\r
256 writer.WriteLine("});")
\r
257 writer.WriteLine("</script>")
\r
259 writer.Write("<div id='" & Me.UniqueId & "_outerDiv'><table id='" & Me.UniqueId & "' border='0' cellspacing='0' cellpadding='0'><tr valign='top'><td rowspan='2'>")
\r
261 '-------------------
\r
263 '-------------------
\r
266 writer.WriteLine("<table id='" & Me.UniqueId & "_tab0h' class='ricoLG_table ricoLG_top ricoLG_left' cellspacing='0' cellpadding='0'><thead>")
\r
267 for r=0 to LastHeadingRow
\r
268 writer.Write("<tr class='" & rows(r).HeadingClass() & "'")
\r
269 if r=ResizeRowIdx then writer.Write(" id='" & Me.UniqueId & "_tab0h_main'")
\r
270 writer.WriteLine(">")
\r
271 if FrozenCols > 0 then writer.Write(rows(r).HeadingRow(0,FrozenCols-1))
\r
272 writer.Write("</tr>")
\r
274 writer.WriteLine("</thead></table>")
\r
276 writer.WriteLine("<div id='" & Me.UniqueId & "_frozenTabsDiv'>")
\r
279 writer.Write("<table id='" & Me.UniqueId & "_tab0' class='ricoLG_table ricoLG_bottom ricoLG_left' cellspacing='0' cellpadding='0'>")
\r
280 writer.WriteLine("<tr>")
\r
281 if FrozenCols > 0 then RenderColumns(writer,0,FrozenCols-1)
\r
282 writer.Write("</tr>")
\r
283 writer.WriteLine("</table>")
\r
285 writer.WriteLine("</div></td>")
\r
288 '-------------------
\r
289 ' scrolling columns
\r
290 '-------------------
\r
293 writer.Write("<td><div id='" & Me.UniqueId & "_innerDiv'>")
\r
294 'writer.Write("<div id='" & Me.UniqueId & "_scrollTabsDiv'>")
\r
295 writer.WriteLine("<table id='" & Me.UniqueId & "_tab1h' class='ricoLG_table ricoLG_top ricoLG_right' cellspacing='0' cellpadding='0'><thead>")
\r
296 for r=0 to LastHeadingRow
\r
297 writer.Write("<tr class='" & rows(r).HeadingClass & "'")
\r
298 if r=ResizeRowIdx then writer.Write(" id='" & Me.UniqueId & "_tab1h_main'")
\r
300 writer.Write(rows(r).HeadingRow(FrozenCols,-1))
\r
301 writer.Write("</tr>")
\r
303 writer.Write("</thead></table>")
\r
304 'writer.Write("</div>")
\r
305 writer.WriteLine("</div></td></tr>")
\r
308 writer.Write("<tr valign='top'><td><div id='" & Me.UniqueId & "_scrollDiv'>")
\r
309 writer.Write("<table id='" & Me.UniqueId & "_tab1' class='ricoLG_table ricoLG_bottom ricoLG_right' cellspacing='0' cellpadding='0'>")
\r
310 writer.WriteLine("<tr>")
\r
311 RenderColumns(writer,FrozenCols,colcnt-1)
\r
312 writer.Write("</tr>")
\r
313 writer.Write("</table>")
\r
314 writer.Write("</div></td></tr>")
\r
316 writer.WriteLine("</table></div>")
\r
319 ' Response.Buffer must be true
\r
320 Public Sub RenderExcel(fileName)
\r
321 Dim r as Integer, c as Integer
\r
322 Dim sw As New System.IO.StringWriter
\r
324 HttpContext.Current.Response.Clear()
\r
325 if fileName<>"" then HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & fileName)
\r
326 HttpContext.Current.Response.ContentType = "application/ms-excel"
\r
329 sw.WriteLine("<table>")
\r
330 for r=0 to rows.count-1
\r
331 sw.WriteLine("<tr>")
\r
332 for c=0 to rows(r).CellCount()-1
\r
333 sw.Write(rows(r).cells(c).HtmlCell())
\r
335 sw.WriteLine("</tr>")
\r
337 sw.WriteLine("</table></div>")
\r
338 HttpContext.Current.Response.Write(sw.ToString)
\r
339 HttpContext.Current.Response.End()
\r
342 ' Response.Buffer must be true
\r
343 Public Sub RenderDelimited(fileName,delim,SubstituteChar)
\r
344 Dim r as Integer, c as Integer
\r
345 Dim sw As New System.IO.StringWriter
\r
347 HttpContext.Current.Response.Clear()
\r
348 if fileName<>"" then HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & fileName)
\r
349 HttpContext.Current.Response.ContentType = "text/csv"
\r
352 for r=0 to rows.count-1
\r
353 for c=0 to rows(r).CellCount()-1
\r
354 if c > 0 then sw.Write(delim)
\r
355 sw.Write(replace(rows(r).cells(c).content,delim,SubstituteChar))
\r
359 HttpContext.Current.Response.Write(sw.ToString)
\r
360 HttpContext.Current.Response.End()
\r
363 Public Class GridContainer
\r
365 Implements INamingContainer
\r