private static void EndRow(Row row, WebGridHtmlWriter writer) { writer.Write("</tr>"); if (row.PostRowHtml != null) { if (row.PostRowHtml is string) { writer.Write((string)row.PostRowHtml); } else if (row.PostRowHtml is Control) { writer.Write((Control)row.PostRowHtml); } } }
private void ApplyAjaxLoader(WebGridHtmlWriter mywriter) { if (!m_Grid.EnableCallBack || (m_Grid.Scripts != null && m_Grid.Scripts.DisableAjaxLoader)) { return; } if (m_Grid.IsUsingJQueryUICSSFramework) { mywriter.Write("<div class=\"ui-widget-overlay wgAjaxLoader\">"); } else { mywriter.Write("<div class=\"wgAjaxLoader\">"); } if (m_Grid.AjaxLoaderTemplate == null) { string img = "Loading."; if (Grid.GotHttpContext) { img = string.Format("<img title=\"Loading data\" alt=\"Loading=\" src=\"{0}\" />", m_Grid.Page.ClientScript.GetWebResourceUrl(GetType(), "WebGrid.Resources.images.loading.gif") .Replace("&", "&")); } mywriter.Write("<div class=\"wgAjaxLoaderContent\" id=\"{0}_AjaxLoader\">{1}</div>", m_Grid.ID, img); } else { mywriter.Write("<div class=\"wgAjaxLoaderContent\" id=\"{0}_AjaxLoader\">", m_Grid.ID); mywriter.Write(m_Grid.AjaxLoaderTemplate); mywriter.Write("</div>"); } mywriter.Write("</div>"); }
internal override void RenderLabelView(HtmlTextWriter writer, RowCell cell) { if (!Grid.EnableCallBack) { throw new GridException("WebGrid must have callback enabled to use tooltip columns, you can enable this by setting 'Grid.EnableCallBack=true'"); } string clientId = ToolTipClientId ?? string.Format("{0}{1}TP{2}", Grid.ID, ColumnId, cell.Row.RowIndex); string closebutton = null; if (CloseButtonText != null) { closebutton = string.Format(",button: '{0}'", CloseButtonText); } Grid.AddClientScript(writer, string.Format(template, clientId, Grid.ClientID, ShowMethod, HideMethod, ToolTipWidth, ToolTipHeight, string.Format("{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues) , ToolTipStyle, SingleToolTip.ToString().ToLower(), ContentText, Title, closebutton)); LabelHtml(string.Format("<div class=\"wgtoolelement\" id=\"{0}{1}TP{2}\">{3}</div>", Grid.ID, ColumnId, cell.Row.RowIndex, Text), writer, cell); }
internal static void CreateTitle(Grid grid, DisplayView mode, WebGridHtmlWriter writer, int[] sortedColumnID, int editMaxCells, string tagstyle) { string strclass = "wgtitlegrid"; if (mode == DisplayView.Detail) { strclass = "wgtitledetail"; } bool isHeader = GetIsHeader(grid); if (!isHeader) { return; } if (grid.IsUsingJQueryUICSSFramework && grid.DisplayView == DisplayView.Detail) { writer.Write("<tr class=\"ui-widget-header wgrow\">"); } else { writer.Write("<tr class=\"wgrow\">"); } ColumnHeader header = new ColumnHeader { m_ColumnSpan = (mode == DisplayView.Grid ? sortedColumnID.Length : editMaxCells), m_Class = string.Format("{0} wgheadercell", strclass) }; header.RenderBeginTag(writer, null, null, string.Format("<{0}", tagstyle)); writer.Write(grid.Title); header.RenderEndTag(writer, string.Format("</{0}>", tagstyle)); writer.Write("</tr>"); }
private void ApplyAjaxLoader(WebGridHtmlWriter mywriter) { if (!m_Grid.EnableCallBack || (m_Grid.Scripts != null && m_Grid.Scripts.DisableAjaxLoader) ) return; if (m_Grid.IsUsingJQueryUICSSFramework) mywriter.Write("<div class=\"ui-widget-overlay wgAjaxLoader\">"); else mywriter.Write("<div class=\"wgAjaxLoader\">"); if (m_Grid.AjaxLoaderTemplate == null) { string img = "Loading."; if (Grid.GotHttpContext) img = string.Format("<img title=\"Loading data\" alt=\"Loading=\" src=\"{0}\" />", m_Grid.Page.ClientScript.GetWebResourceUrl(GetType(), "WebGrid.Resources.images.loading.gif") .Replace("&", "&")); mywriter.Write("<div class=\"wgAjaxLoaderContent\" id=\"{0}_AjaxLoader\">{1}</div>", m_Grid.ID, img); } else { mywriter.Write("<div class=\"wgAjaxLoaderContent\" id=\"{0}_AjaxLoader\">", m_Grid.ID); mywriter.Write( m_Grid.AjaxLoaderTemplate); mywriter.Write("</div>"); } mywriter.Write("</div>"); }
private static void StartNewRow(Row row, string style, WebGridHtmlWriter writer) { Grid grid = row.m_Table.m_Grid; StringBuilder js = new StringBuilder(string.Empty); string onmouseover = string.Empty; string onmouseout = string.Empty; if (grid.RowHighLight != Color.Empty) { row.RowHighLight = grid.RowHighLight; if (row.RowHighLight != Color.Empty) { onmouseover += string.Format("wgrowhighlight(this, 'over', '{0}');", Grid.ColorToHtml(grid.RowHighLight)); onmouseout += "wgrowhighlight(this,'','');"; } } #region Client Row Events if (!string.IsNullOrEmpty(grid.OnClientRowClick)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowClick }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowclick", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); js.AppendFormat(@" onclick=""{0}(this,{1});return false"" ", grid.OnClientRowClick, jsonId); } if (!string.IsNullOrEmpty(grid.OnClientRowDblClick)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowDblClick }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowdblclick", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); js.AppendFormat(@" ondblclick=""{0}(this,{1});return false"" ", grid.OnClientRowDblClick, jsonId); } if (!string.IsNullOrEmpty(grid.OnClientRowMouseOut)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowMouseOut }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowmouseout", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); onmouseout += string.Format(@"{0}(this,{1}); ", grid.OnClientRowMouseOut, jsonId); } if (!string.IsNullOrEmpty(grid.OnClientRowMouseOver)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowMouseOver }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowmouseout", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); onmouseover += string.Format(@"{0}(this,{1}); ", grid.OnClientRowMouseOver, jsonId); } if (!string.IsNullOrEmpty(onmouseover)) js.AppendFormat(@" onmouseover=""{0}""", onmouseover); if (!string.IsNullOrEmpty(onmouseout)) js.AppendFormat(@" onmouseout=""{0}""", onmouseout); #endregion if (row.PreRowHtml != null) if (row.PreRowHtml is string) writer.Write((string) row.PreRowHtml); else if (row.PreRowHtml is Control) writer.Write((Control) row.PreRowHtml); if (grid.RecordsPerRow > 1) { grid.m_RowsAdded++; writer.Write("<tr class=\"wgrow\" id=\"{0}r{1}\" {2} class=\"{3} {4}\">", row.m_Table.m_Grid.ID, grid.m_RowsAdded, js.ToString(), style, row.CssClass); } else writer.Write("<tr class=\"wgrow\" id=\"{0}r{1}\" {2} class=\"{3} {4}\">", row.m_Table.m_Grid.ID, row.RowIndex, js.ToString(), style, row.CssClass); }
private static void CreateTotalSummary(Grid grid, WebGridHtmlWriter writer, int[] sortedColumnID) { if (grid.MasterTable.Rows.Count == 0) return; int firstSumColumn = GetFirstSummary(sortedColumnID, grid); if (firstSumColumn == sortedColumnID.Length) return; string columnId = null; foreach (int ii in sortedColumnID) { Column column = grid.MasterTable.Columns[ii]; if (column.ColumnType == ColumnType.SystemColumn) continue; columnId = column.ColumnId; break; } if (string.IsNullOrEmpty(columnId)) columnId = grid[firstSumColumn].ColumnId; grid.m_RowsAdded++; if(!grid.IsUsingJQueryUICSSFramework) writer.Write( "<tr id=\"{0}r{1}\" class=\"wgrow\"><td colspan=\"{2}\" id=\"{0}{4}r{1}\" class=\"wgtotal\">{3}</td>", grid.ID, grid.m_RowsAdded, firstSumColumn, grid.GetSystemMessage("TotalSummary"), columnId); else { writer.Write( "<tr id=\"{0}r{1}\" class=\"ui-state-highlight wgrow\"><td colspan=\"{2}\" id=\"{0}{4}r{1}\" class=\"wgtotal\">{3}</td>", grid.ID, grid.m_RowsAdded, firstSumColumn, grid.GetSystemMessage("TotalSummary"), columnId); } grid.MasterTable[0].m_RowIndex = grid.m_RowsAdded; for (int ii = firstSumColumn; ii < sortedColumnID.Length; ii++) { grid.MasterTable.Columns[sortedColumnID[ii]].Grid = grid; RowCell cell = grid.MasterTable[0][sortedColumnID[ii]]; Column column = grid.MasterTable.Columns[sortedColumnID[ii]]; if (column.ColumnType == ColumnType.Decimal && ((WebGrid.Decimal)column).DisplayTotalSummary) { column.CssClass = "wgtotalcell"; column.AllowEdit = false; if (grid.Trace.IsTracing) grid.Trace.Trace("TotalSummary for column '{0}' is {1}", column.ColumnId, ((WebGrid.Decimal)column).TotalSum); cell.Value = ((WebGrid.Decimal)column).TotalSum; ((WebGrid.Decimal)column).Sum = null; column.Visibility = Visibility.Grid; column.Render(writer, cell); column.CssClass = null; } else { writer.Write("<td id=\"{0}{1}r{2}\" class=\"wgtotal\"> </td>", grid.ID, column.ColumnId, grid.MasterTable[0].m_RowIndex); } } writer.Write("</tr>"); }
private static void CreateGridToolbar(string toolbar, WebGridHtmlWriter writer, Grid grid) { if (toolbar.IndexOf("[NEWRECORD]", StringComparison.OrdinalIgnoreCase) > -1) { if (grid.AllowNew) { bool allownew = false; for (int i = 0; i < grid.MasterTable.Columns.Count; i++) if (grid.MasterTable.Columns[i].AllowEdit && grid.MasterTable.Columns[i].IsInDataSource && (grid.MasterTable.Columns[i].Visibility == Visibility.Both || grid.MasterTable.Columns[i].Visibility == Visibility.Detail)) { allownew = true; break; } toolbar = allownew ? toolbar.Replace("[NEWRECORD]", CreateNewPostButton(grid)) : toolbar.Replace("[NEWRECORD]", string.Empty); } else toolbar = toolbar.Replace("[NEWRECORD]", string.Empty); } if (toolbar.IndexOf("[CLOSEWINDOW]", StringComparison.OrdinalIgnoreCase) > -1) { if (grid.m_MasterWebGrid != null && grid.m_MasterWebGrid.DisplaySlaveGridMenu && grid.m_IsGridInsideGrid == false) { toolbar = toolbar.Replace("[CLOSEWINDOW]", ( Buttons.TextButtonControl(grid, grid.GetSystemMessage("CloseWindow"), "RecordCancelClick", new[] { string.Format("{0}!{1}", grid.InternalId, grid. m_IsOneToOneRelationGrid) } , grid.GetSystemMessageClass("CloseWindow", "wgclosewindow")))); } else toolbar = toolbar.Replace("[CLOSEWINDOW]", string.Empty); } if (toolbar.IndexOf("[UPDATEROWS]", StringComparison.OrdinalIgnoreCase) > -1) { toolbar = grid.AllowUpdateRows ? toolbar.Replace("[UPDATEROWS]", CreateUpdateRowsButton(grid)) : toolbar.Replace("[UPDATEROWS]", string.Empty); } if (toolbar.IndexOf("[SEARCHFIELD]", StringComparison.OrdinalIgnoreCase) > -1) { toolbar = grid.DisplaySearchBox != Position.Hide ? toolbar.Replace("[SEARCHFIELD]", CreateSearchField(grid)) : toolbar.Replace("[SEARCHFIELD]", string.Empty); } if (toolbar.IndexOf("[PAGER]", StringComparison.OrdinalIgnoreCase) > -1) { if (grid.PagerSettings.PagerType != PagerType.None && grid.RecordCount > grid.PageSize) { string pager = CreatePager(grid); if (string.IsNullOrEmpty(pager) == false) pager = string.Format( "<table class=\"wgpager\"><tr><td>{0}</td><td>{1}</td></tr></table>", grid.PagerPrefix, pager); toolbar = toolbar.Replace("[PAGER]", pager); } else toolbar = toolbar.Replace("[PAGER]", string.Empty); } if (toolbar.IndexOf("[PAGERSTATUS]", StringComparison.OrdinalIgnoreCase) > -1) toolbar = PagerType.None != grid.PagerSettings.PagerType && grid.RecordCount > grid.PageSize ? toolbar.Replace("[PAGERSTATUS]", grid.PagerSettings.GetPagerStatus) : toolbar.Replace("[PAGERSTATUS]", string.Empty); if (string.IsNullOrEmpty(toolbar) == false) writer.Write(toolbar); }
internal void RenderGrid(ref Grid grid, ref WebGridHtmlWriter writer) { string width = grid.Width.IsEmpty == false ? grid.Width.ToString() : "100%"; /* cellpadding and cellspacing are fixed because CSS does not support similar behavior*/ if (grid.IsUsingJQueryUICSSFramework) writer.Write( "<table width=\"{0}\" id=\"{1}\" class=\"ui-widget-content\" cellpadding=\"0\" cellspacing=\"0\">", width, grid.ID); else writer.Write( "<table width=\"{0}\" id=\"{1}\" cellpadding=\"0\" cellspacing=\"0\">", width, grid.ID); int[] sortedColumns = grid.VisibleSortedColumns; if (grid.RecordsPerRow == 1) { //extra table is to get rid of css background glitch in ie and safari. if (grid.IsUsingJQueryUICSSFramework) writer.Write("<thead class=\"ui-widget-header wgthead\">"); else writer.Write("<thead class=\"wgthead\">"); } CreateTitle(grid, DisplayView.Grid, writer, sortedColumns, 0, "th"); if ((grid.CollapseIfSlaveGrid && grid.ActiveMenuSlaveGrid != null) || grid.CollapsedGrid) { if (grid.RecordsPerRow == 1) writer.Write("</thead></table>"); else writer.Write("</table>"); return; } if (grid.MasterTable.Columns.Primarykeys == null) { grid.AllowDelete = false; grid.AllowEdit = false; grid.AllowNew = false; grid.AllowCopy = false; } if (string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarGridTop)) == false) { if (grid.IsUsingJQueryUICSSFramework) writer.Write("<tr class=\"ui-widget-header wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); else writer.Write("<tr class=\"wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); CreateGridToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarGridTop), writer, grid); writer.Write("</td></tr>"); } // Show Header bool FilterByColumns = grid.MasterTable.Columns.Exists(delegate(Column column) { return column.FilterByColumnCollection != null && column.FilterByColumnCollection.Count > 0;}); // Create column filter if (FilterByColumns) CreateFilterByColumns(grid, writer, sortedColumns); // RENDER ROWS if (grid.DisplayHeader) { // CREATE HEADING writer.Write("<tr valign=\"bottom\" class=\"wgrow wggridheader\" id=\"{0}r0\">", grid.ID); for (int ii = 0; ii < sortedColumns.Length; ii++) { Column column = grid.MasterTable.Columns[sortedColumns[ii]]; ColumnHeader addcolumn = new ColumnHeader { m_Class = string.Format("{0} wgheadercell", column.CssClassTitle), m_Align = column.GridAlign, m_VAlign = VerticalPosition.bottom, m_GridRowCount = (-1), m_GridId = grid.ID }; if ((column.ColumnType == ColumnType.SystemColumn && ((WebGrid.SystemColumn) column).SystemColumnType == SystemColumn.SpacingColumn) == false) { if (column.WidthColumnHeaderTitle == Unit.Empty) { switch (column.ColumnType) { case ColumnType.SystemColumn: addcolumn.m_ColumnWidth = Unit.Percentage(1); break; case ColumnType.Decimal: case ColumnType.Number: { int columnwidth = column.Title.Length*12; if (columnwidth > 200) columnwidth = 200; addcolumn.m_ColumnWidth = Unit.Pixel(columnwidth); } break; } // else // addcolumn.ColumnWidth = Unit.Pixel(100); } else addcolumn.m_ColumnWidth = column.WidthColumnHeaderTitle; grid[column.ColumnId].WidthColumnHeaderTitle = addcolumn.m_ColumnWidth; } addcolumn.RenderBeginTag(writer, column, null, "<th"); // writer.Write("<div class=\"wgheadercell\" id=\"{0}h{1}\">", grid.ID, column.ColumnId); if (column.UseAllRows && (grid.SelectableRows || grid.RowHighLight != Color.Empty)) { grid.RowHighLight = Color.Empty; grid.SelectableRows = false; } if (column.IsInDataSource && column.Sortable) { string[] arrayParams = new string[1]; if (grid.MasterTable.DataSource != null) arrayParams[0] = column.ColumnId; else /*if (column.ColumnType == ColumnType.Foreignkey || !string.IsNullOrEmpty(grid.Sql))*/ arrayParams[0] = Interface.BuildTableElement(true, column.m_Table.DataSourceId,column.ColumnId); /*else { Foreignkey fk = (Foreignkey) column; arrayParams[0] = Foreignkey.BuildDisplayTextSql( string.Format(" [_pk{0}_{1}].", sortedColumns[ii], fk.DataSourceId), fk.ValueColumn, string.Empty, true, fk.Table); if (fk.Table.DataSource != null) arrayParams[0] = fk.ColumnId; }*/ string columnHeaderText = column.HeaderText; if (string.IsNullOrEmpty(column.ToolTipGridHeaderText) == false) columnHeaderText = Tooltip.Add(columnHeaderText, column.ToolTipGridHeaderText); StringBuilder hyperlink; if (!grid.AllowSort) hyperlink = new StringBuilder( String.Format("<span class=\"{1}\">{0}</span>", columnHeaderText, null)); else { string sortimage = string.Empty; // Up/down images if (grid.DisplaySortIcons && grid.MasterTable.OrderBySortList[arrayParams[0]] != null) { /*StringBuilder img = new StringBuilder("sort-"); if (grid.MasterTable.OrderBySortList[arrayParams[0]].m_Desc) img.Append("down"); else img.Append("up"); if (grid.MasterTable.OrderBySortList[arrayParams[0]].m_DisplayIndex != 0) img.Append("2"); img.Append(".gif"); string sort = string.Format(" <img style=\" border:0px\" alt=\"{0}\" src=\"{1}{2}\" />", grid.GetSystemMessage("SortIcon"), grid.ImagePath, img);*/ if (grid.MasterTable.OrderBySortList[arrayParams[0]].m_Desc) sortimage = string.Format( @"<span title=""{0}"" style=""float:left"" class=""ui-icon ui-icon-triangle-1-s""/>", grid.GetSystemMessage("SortIcon")); else sortimage = string.Format( @"<span title=""{0}"" style=""float:left"" class=""ui-icon ui-icon-triangle-1-n""/>", grid.GetSystemMessage("SortIcon")); } hyperlink = new StringBuilder("<table cellspacing=\"0\" cellpadding=\"0\"><tr><td>"); hyperlink.Append(new StringBuilder( Buttons.Anchor(grid, columnHeaderText, "ColumnHeaderClick", arrayParams, null, null, null, null, false))); hyperlink.Append("</td><td>"); hyperlink.Append(sortimage); hyperlink.Append("</td></tr></table>"); } if (grid.NonBreakingHeaders) { hyperlink.Insert(0, "<span class=\"wgnowrap\">"); hyperlink.Append("</span>"); } writer.Write(hyperlink.ToString()); } else { string css = string.Empty; if (grid.NonBreakingHeaders) css += " wgnowrap"; writer.Write("<span class=\"{0}\">{1}</span>", css, column.HeaderText); } addcolumn.RenderEndTag(writer, "</th>"); } writer.Write("</tr>"); // FINISH CREATE HEADING } if (grid.RecordsPerRow == 1) writer.Write("</thead>"); bool tree = !string.IsNullOrEmpty(grid.TreeParentId); writer.Write(grid.BeforeRowsEvent()); if (grid.Trace.IsTracing) grid.Trace.Trace("Started Rendering Rows ({0})", grid.ID); writer.Write("<tbody>"); CreateRows(grid, tree, null, 0, writer, sortedColumns, 0); if (grid.RecordsPerRow == 1) CreateTotalSummary(grid, writer, sortedColumns); if (grid.Trace.IsTracing) grid.Trace.Trace("Stopped Rendering Rows ({0}).", grid.ID); writer.Write(grid.AfterRowsEvent()); writer.Write("</tbody>"); if (!string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarGridBottom))) { writer.Write("<tfoot>"); if (grid.IsUsingJQueryUICSSFramework) writer.Write("<tr class=\"ui-widget-header wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); else writer.Write("<tr class=\"wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); CreateGridToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarGridBottom), writer, grid); writer.Write("</td></tr></tfoot>"); } writer.Write("</table>"); if (grid.Page != null) if (grid.EnableCallBack) writer.Write("<input type=\"hidden\" id=\"{0}checkboxes\" name=\"{0}checkboxes\" value=\"{1}\" />", grid.ClientID, m_Checkboxlist.ToString()); else grid.Page.ClientScript.RegisterHiddenField(string.Format("{0}checkboxes", grid.ClientID), m_Checkboxlist.ToString()); }
public void RenderEndTag(WebGridHtmlWriter writer, string tagtype) { writer.Write(tagtype); }
private void ApplyInternalValues(RowCell cell, Control ctrl) { foreach (Control control in ctrl.Controls) { if (control is LiteralControl == false) continue; LiteralControl ctr = control as LiteralControl; if (ctr == null) continue; string innerhtml = ctr.Text; if (!string.IsNullOrEmpty(innerhtml) && innerhtml.IndexOf(string.Format("[{0}]", ColumnId), StringComparison.OrdinalIgnoreCase) != -1) throw new GridException( string.Format("The template '{0}' can't contain reference to itself.", ColumnId)); if (string.IsNullOrEmpty(innerhtml) || !innerhtml.Contains("[")) continue; string content = innerhtml; cell.Row.Columns.ForEach(delegate(Column column) { if ( content.IndexOf(string.Format("[{0}]", column.ColumnId), StringComparison.OrdinalIgnoreCase) == -1) return; WebGridHtmlWriter writer = new WebGridHtmlWriter(Grid); Visibility columnvisibility = column.Visibility; column.Visibility = Visibility; column.SystemMessageStyle = SystemMessageStyle.WebGrid; if (Grid.Trace.IsTracing) Grid.Trace.Trace( "Rendering ColumnName: {0} in column: {1}", column.ColumnId, ColumnId); column.RenderEditView(writer, cell.Row.Cells[column.ColumnId]); column.Visibility = columnvisibility; if (column.AllowEdit) writer.Write( "<input type=\"hidden\" value=\"validate\" name=\"{0}_{1}_validate\" />", Grid.ClientID, column.ColumnId); content = content.Replace(string.Format("[{0}]", column.ColumnId), writer.ToString()); }); ((LiteralControl)control).Text = content; } }
internal void GetContextMenuHtml(WebGridHtmlWriter writer) { if (Page == null) return; writer.Write(@"<ul id=""{0}_Menu"" class=""wgcontextMenu"">", ID); if (m_ContextMenu == null || !m_ContextMenu.Contains(ContextMenuType.Help)) { AddClientScript(writer, "$(document).ready(function() {$(\".wghelpiframe\").colorbox({ width: \"400px\", height: \"675px\", iframe: true });});"); writer.Write(@"<li class=""wgcontextmenuhelp""><a {0}>Display Help</a></li>", AddMenuAction(ContextMenuType.Help)); } if (m_ContextMenu == null || !m_ContextMenu.Contains(ContextMenuType.Export)) writer.Write(@"<li class=""wgcontextmenuexport separator""><a {0}>Export Data</a></li>", AddMenuAction(ContextMenuType.Export)); if (m_ContextMenu == null || !m_ContextMenu.Contains(ContextMenuType.Refresh)) writer.Write(@"<li class=""wgcontextmenurefresh""><a {0}>Refresh Data</a></li>", AddMenuAction(ContextMenuType.Refresh)); if (m_ContextMenu == null || !m_ContextMenu.Contains(ContextMenuType.CollapsedGrid)) { string text = CollapsedGrid ? "Expand Grid" : "Collapse Grid"; writer.Write(@"<li class=""wgcontextmenucollapse separator""><a {0}>{1}</a></li>", AddMenuAction(ContextMenuType.CollapsedGrid), text); } if (ActiveMenuSlaveGrid != null) writer.Write(@"<li class=""wgcontextmenucollapse""><a {0}>Close slave grid</a></li>", AddMenuAction(ContextMenuType.ActiveSlaveGrid)); if (m_ContextMenu == null || !m_ContextMenu.Contains(ContextMenuType.Print)) writer.Write(@"<li class=""wgcontextmenuprint""><a {0}>Print this grid</a></li>", AddMenuAction(ContextMenuType.Print)); if (m_ContextMenu == null || !m_ContextMenu.Contains(ContextMenuType.About)) { AddClientScript(writer, "$(document).ready(function() {$(\".wgaboutiframe\").colorbox({ width: \"475px\", height: \"300px\", iframe: true });});"); writer.Write(@"<li class=""wgcontextmenuhelp"" class=""wgcontextmenuabout""><a {0}>About WebGrid</a></li>", AddMenuAction(ContextMenuType.About)); } if (IsDemo) writer.Write(@"<li><a onclick=""alert('For full version register at www.webgrid.com');"">WebGrid Demo</a></li>"); if (m_ContextMenu != null) foreach (ContextMenuItem item in ContextMenu) { if (!item.Visible || string.IsNullOrEmpty(item.Text)) continue; writer.Write("<li "); if (item.CssClass != null) writer.Write(@" class=""{0}""", item.CssClass); if (item.Id != null) writer.Write(@" id=""{0}""", item.Id); writer.Write(@"><a {1}>{0}</a></li>", item.Text, item.InternalMenuType != ContextMenuType.Undefined ? AddMenuAction(item.InternalMenuType) : ((CustomMenuItem) item).Attributes); } writer.Write("</ul>"); }
private static void CreateTotalSummary(Grid grid, WebGridHtmlWriter writer, int[] sortedColumnID) { if (grid.MasterTable.Rows.Count == 0) { return; } int firstSumColumn = GetFirstSummary(sortedColumnID, grid); if (firstSumColumn == sortedColumnID.Length) { return; } string columnId = null; foreach (int ii in sortedColumnID) { Column column = grid.MasterTable.Columns[ii]; if (column.ColumnType == ColumnType.SystemColumn) { continue; } columnId = column.ColumnId; break; } if (string.IsNullOrEmpty(columnId)) { columnId = grid[firstSumColumn].ColumnId; } grid.m_RowsAdded++; if (!grid.IsUsingJQueryUICSSFramework) { writer.Write( "<tr id=\"{0}r{1}\" class=\"wgrow\"><td colspan=\"{2}\" id=\"{0}{4}r{1}\" class=\"wgtotal\">{3}</td>", grid.ID, grid.m_RowsAdded, firstSumColumn, grid.GetSystemMessage("TotalSummary"), columnId); } else { writer.Write( "<tr id=\"{0}r{1}\" class=\"ui-state-highlight wgrow\"><td colspan=\"{2}\" id=\"{0}{4}r{1}\" class=\"wgtotal\">{3}</td>", grid.ID, grid.m_RowsAdded, firstSumColumn, grid.GetSystemMessage("TotalSummary"), columnId); } grid.MasterTable[0].m_RowIndex = grid.m_RowsAdded; for (int ii = firstSumColumn; ii < sortedColumnID.Length; ii++) { grid.MasterTable.Columns[sortedColumnID[ii]].Grid = grid; RowCell cell = grid.MasterTable[0][sortedColumnID[ii]]; Column column = grid.MasterTable.Columns[sortedColumnID[ii]]; if (column.ColumnType == ColumnType.Decimal && ((WebGrid.Decimal)column).DisplayTotalSummary) { column.CssClass = "wgtotalcell"; column.AllowEdit = false; if (grid.Trace.IsTracing) { grid.Trace.Trace("TotalSummary for column '{0}' is {1}", column.ColumnId, ((WebGrid.Decimal)column).TotalSum); } cell.Value = ((WebGrid.Decimal)column).TotalSum; ((WebGrid.Decimal)column).Sum = null; column.Visibility = Visibility.Grid; column.Render(writer, cell); column.CssClass = null; } else { writer.Write("<td id=\"{0}{1}r{2}\" class=\"wgtotal\"> </td>", grid.ID, column.ColumnId, grid.MasterTable[0].m_RowIndex); } } writer.Write("</tr>"); }
private static void CreateGridToolbar(string toolbar, WebGridHtmlWriter writer, Grid grid) { if (toolbar.IndexOf("[NEWRECORD]", StringComparison.OrdinalIgnoreCase) > -1) { if (grid.AllowNew) { bool allownew = false; for (int i = 0; i < grid.MasterTable.Columns.Count; i++) { if (grid.MasterTable.Columns[i].AllowEdit && grid.MasterTable.Columns[i].IsInDataSource && (grid.MasterTable.Columns[i].Visibility == Visibility.Both || grid.MasterTable.Columns[i].Visibility == Visibility.Detail)) { allownew = true; break; } } toolbar = allownew ? toolbar.Replace("[NEWRECORD]", CreateNewPostButton(grid)) : toolbar.Replace("[NEWRECORD]", string.Empty); } else { toolbar = toolbar.Replace("[NEWRECORD]", string.Empty); } } if (toolbar.IndexOf("[CLOSEWINDOW]", StringComparison.OrdinalIgnoreCase) > -1) { if (grid.m_MasterWebGrid != null && grid.m_MasterWebGrid.DisplaySlaveGridMenu && grid.m_IsGridInsideGrid == false) { toolbar = toolbar.Replace("[CLOSEWINDOW]", ( Buttons.TextButtonControl(grid, grid.GetSystemMessage("CloseWindow"), "RecordCancelClick", new[] { string.Format("{0}!{1}", grid.InternalId, grid. m_IsOneToOneRelationGrid) } , grid.GetSystemMessageClass("CloseWindow", "wgclosewindow")))); } else { toolbar = toolbar.Replace("[CLOSEWINDOW]", string.Empty); } } if (toolbar.IndexOf("[UPDATEROWS]", StringComparison.OrdinalIgnoreCase) > -1) { toolbar = grid.AllowUpdateRows ? toolbar.Replace("[UPDATEROWS]", CreateUpdateRowsButton(grid)) : toolbar.Replace("[UPDATEROWS]", string.Empty); } if (toolbar.IndexOf("[SEARCHFIELD]", StringComparison.OrdinalIgnoreCase) > -1) { toolbar = grid.DisplaySearchBox != Position.Hide ? toolbar.Replace("[SEARCHFIELD]", CreateSearchField(grid)) : toolbar.Replace("[SEARCHFIELD]", string.Empty); } if (toolbar.IndexOf("[PAGER]", StringComparison.OrdinalIgnoreCase) > -1) { if (grid.PagerSettings.PagerType != PagerType.None && grid.RecordCount > grid.PageSize) { string pager = CreatePager(grid); if (string.IsNullOrEmpty(pager) == false) { pager = string.Format( "<table class=\"wgpager\"><tr><td>{0}</td><td>{1}</td></tr></table>", grid.PagerPrefix, pager); } toolbar = toolbar.Replace("[PAGER]", pager); } else { toolbar = toolbar.Replace("[PAGER]", string.Empty); } } if (toolbar.IndexOf("[PAGERSTATUS]", StringComparison.OrdinalIgnoreCase) > -1) { toolbar = PagerType.None != grid.PagerSettings.PagerType && grid.RecordCount > grid.PageSize ? toolbar.Replace("[PAGERSTATUS]", grid.PagerSettings.GetPagerStatus) : toolbar.Replace("[PAGERSTATUS]", string.Empty); } if (string.IsNullOrEmpty(toolbar) == false) { writer.Write(toolbar); } }
private static void CreateDetailToolbar(string toolbar, WebGridHtmlWriter writer, Grid grid, bool editablecolumns) { if (toolbar.IndexOf("[UPDATE]", StringComparison.OrdinalIgnoreCase) > -1) { if (editablecolumns) { string updatemessage = grid.StayInDetail || grid.m_IsGridInsideGrid ? "Update" : "UpdateClose"; string status = string.Empty; if (grid.m_IsOneToOneRelationGrid && grid.m_IsOneToOneRelationNewRecord) { status = "!new"; } if (grid.m_IsOneToOneRelationGrid && grid.m_IsOneToOneRelationNewRecord == false) { status = "!update"; } toolbar = toolbar.Replace("[UPDATE]", ( Buttons.TextButtonControl(grid, grid.GetSystemMessage(updatemessage), "RecordUpdateClick", new[] { string.Format("{0}!{1}{2}", grid.InternalId, grid.m_IsCopyClick, status) }, grid.GetSystemMessageClass(updatemessage, "wgupdaterecord"), null, grid.ID + "_wgupdaterecord"))); } else { toolbar = toolbar.Replace("[UPDATE]", string.Empty); } } if (toolbar.IndexOf("[CLOSEWINDOW]", StringComparison.OrdinalIgnoreCase) > -1) { if ((grid.MasterWebGrid != null && !grid.m_IsGridInsideGrid) || (grid.ActiveMenuSlaveGrid == null || (grid.m_HasGridInsideGrid && grid.ActiveMenuSlaveGrid == null)) && (grid.AllowCancel) || (grid.m_IsGridInsideGrid && grid.AllowCancel)) { if ((grid.MasterWebGrid != null && grid.m_IsGridInsideGrid == false) && grid.AllowCancel == false) { grid.m_IsOneToOneRelationGrid = true; } toolbar = toolbar.Replace("[CLOSEWINDOW]", ( Buttons.TextButtonControl(grid, grid.GetSystemMessage("CloseWindow"), "RecordCancelClick", new[] { string.Format("{0}!{1}", grid.InternalId, grid. m_IsOneToOneRelationGrid) } , grid.GetSystemMessageClass("CloseWindow", "wgclosewindow")))); } else { toolbar = toolbar.Replace("[CLOSEWINDOW]", string.Empty); } } if (string.IsNullOrEmpty(toolbar) == false) { writer.Write(toolbar); } }
internal static void RenderDetail(ref Grid grid, ref WebGridHtmlWriter writer) { string width = grid.Width.IsEmpty == false?grid.Width.ToString() : "100%"; /* cellpadding and cellspacing are fixed because CSS does not support similar behavior*/ if (grid.IsUsingJQueryUICSSFramework) { writer.Write( //ui-helper-reset "<table width=\"{0}\" class=\"ui-widget-content wgmaindetail\" cellspacing=\"0\" cellpadding=\"0\">", width); } else { writer.Write("<table width=\"{0}\" class=\"wgmaindetail\" cellspacing=\"0\" cellpadding=\"0\">", width); } int[] sortedColumns = grid.VisibleSortedColumns; int columnWidth = -1; int allRowsColumns = 0; int ant = 0; bool firstvisiblecolumn = true; bool editablecolumns = grid.m_Forceeditablecolumns; for (int i = 0; i < sortedColumns.Length; i++) { ant += 2; // if( Grid.BasicDetailLayout ) // ant--; if (grid.DisplayRequiredColumn) { ant++; } if (ant > columnWidth) { columnWidth = ant; } Column c = grid.MasterTable.Columns[sortedColumns[i]]; if (c.UseAllRows) { allRowsColumns++; } if (c.IsVisible == false) { continue; } if (editablecolumns == false && c.AllowEdit) { editablecolumns = true; } if (firstvisiblecolumn) { firstvisiblecolumn = false; continue; } if (c.NewRowInDetail) { ant = 0; } } // Create head CreateTitle(grid, DisplayView.Detail, writer, sortedColumns, columnWidth, "td"); if ((grid.CollapseIfSlaveGrid && grid.ActiveMenuSlaveGrid != null) || grid.CollapsedGrid) { writer.Write("</table>"); return; } // Create toolbar if (string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarDetailTop)) == false) { if (grid.IsUsingJQueryUICSSFramework) { writer.Write( "<tr class=\"ui-widget-header wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); } else { writer.Write( "<tr class=\"wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); } CreateDetailToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarDetailTop), writer, grid, editablecolumns); writer.Write("</td></tr>"); } int antcols = 0; if (allRowsColumns > 0) { writer.Write( "<tr><td colspan=\"{0}\"><table class=\"wgrowspan\"><tr valign=\"top\"><td><table class=\"wgrowspan\">", columnWidth); } grid.MasterTable.Rows[0].RowIndex = -1; for (int i = 0; i < sortedColumns.Length; i++) { Column column = grid.MasterTable.Rows[0] != null ? grid.MasterTable.Columns[sortedColumns[i]] : grid.MasterTable.Columns[sortedColumns[i]]; if (column.UseAllRows && i > 0) { writer.Write("</table></td><td><table class=\"wgrowspan\">"); } if (i == 0 || (i < sortedColumns.Length && column.NewRowInDetail)) { antcols = 0; writer.Write("<tr class=\"wgrow\">"); } if (!column.HideDetailTitle) { ColumnHeader columnName = new ColumnHeader { m_VAlign = column.EditVAlign, m_Align = column.EditAlignTitle, m_ColumnWidth = column.WidthColumnTitle, m_Class = string.Format("{0} wgdetailheader", column.CssClassTitle), m_GridRowCount = (-1), m_GridId = grid.ID }; if (columnName.m_ColumnWidth == Unit.Empty) { int columnwidth = column.Title.Length * 12; if (columnwidth > 140) { columnwidth = 140; } columnName.m_ColumnWidth = Unit.Pixel(columnwidth); } columnName.RenderBeginTag(writer, column, null, "<td"); if (string.IsNullOrEmpty(column.ToolTipEditTitle)) { writer.Write(column.Title); } else { writer.Write(Tooltip.Add(column.Title, column.ToolTipEditTitle)); } antcols++; if (grid.BasicDetailLayout == false) { columnName.RenderEndTag(writer, "</td>"); } if (grid.DisplayRequiredColumn) { antcols++; ColumnHeader requiredColumn = new ColumnHeader { m_Class = string.Format("wgrequiredcolumn {0}", column.CssClassTitle), m_ColumnWidth = Unit.Pixel(1), m_VAlign = (column.HeightEditableColumn.IsEmpty ? column.EditVAlign : VerticalPosition.top) }; requiredColumn.RenderBeginTag(writer, column, null, "<td"); if (column.Required && column.AllowEdit) { writer.Write(@"<span title=""{0}"" class=""ui-icon ui-icon-info""/>", grid.GetSystemMessage("Required")); } else { writer.Write(" "); } requiredColumn.RenderEndTag(writer, "</td>"); } } antcols++; if ((i == sortedColumns.Length - 1 || (i + 1 < sortedColumns.Length && grid[sortedColumns[i + 1]].NewRowInDetail)) && antcols < columnWidth) { grid.Rows[0][column.ColumnId].InternalCellSpan += columnWidth - antcols; } // column.Row = grid.MasterTable.Rows[0]; column.Render(writer, grid.Rows[0][column.ColumnId]); if (i == sortedColumns.Length - 1 || (i + 1 < sortedColumns.Length && grid[sortedColumns[i + 1]].NewRowInDetail)) { writer.Write("</tr>"); } if (column.UseAllRows) { if (i + 1 < sortedColumns.Length) { writer.Write("</table></td><td><table class=\"wgrowspan\">"); } else { writer.Write("</table>"); } } else if (allRowsColumns > 0 && i + 1 == sortedColumns.Length) { writer.Write("</table>"); } } if (allRowsColumns > 0) { writer.Write("</td></tr></table></td></tr>"); } // Create tail if (string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarDetailBottom)) == false) { if (grid.IsUsingJQueryUICSSFramework) { writer.Write( "<tr class=\"ui-widget-header wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); } else { writer.Write( "<tr class=\"wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); } CreateDetailToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarDetailBottom), writer, grid, editablecolumns); writer.Write("</td></tr>"); } writer.Write("</table>"); }
internal void RenderGrid(ref Grid grid, ref WebGridHtmlWriter writer) { string width = grid.Width.IsEmpty == false?grid.Width.ToString() : "100%"; /* cellpadding and cellspacing are fixed because CSS does not support similar behavior*/ if (grid.IsUsingJQueryUICSSFramework) { writer.Write( "<table width=\"{0}\" id=\"{1}\" class=\"ui-widget-content\" cellpadding=\"0\" cellspacing=\"0\">", width, grid.ID); } else { writer.Write( "<table width=\"{0}\" id=\"{1}\" cellpadding=\"0\" cellspacing=\"0\">", width, grid.ID); } int[] sortedColumns = grid.VisibleSortedColumns; if (grid.RecordsPerRow == 1) { //extra table is to get rid of css background glitch in ie and safari. if (grid.IsUsingJQueryUICSSFramework) { writer.Write("<thead class=\"ui-widget-header wgthead\">"); } else { writer.Write("<thead class=\"wgthead\">"); } } CreateTitle(grid, DisplayView.Grid, writer, sortedColumns, 0, "th"); if ((grid.CollapseIfSlaveGrid && grid.ActiveMenuSlaveGrid != null) || grid.CollapsedGrid) { if (grid.RecordsPerRow == 1) { writer.Write("</thead></table>"); } else { writer.Write("</table>"); } return; } if (grid.MasterTable.Columns.Primarykeys == null) { grid.AllowDelete = false; grid.AllowEdit = false; grid.AllowNew = false; grid.AllowCopy = false; } if (string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarGridTop)) == false) { if (grid.IsUsingJQueryUICSSFramework) { writer.Write("<tr class=\"ui-widget-header wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); } else { writer.Write("<tr class=\"wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); } CreateGridToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarGridTop), writer, grid); writer.Write("</td></tr>"); } // Show Header bool FilterByColumns = grid.MasterTable.Columns.Exists(delegate(Column column) { return(column.FilterByColumnCollection != null && column.FilterByColumnCollection.Count > 0); }); // Create column filter if (FilterByColumns) { CreateFilterByColumns(grid, writer, sortedColumns); } // RENDER ROWS if (grid.DisplayHeader) { // CREATE HEADING writer.Write("<tr valign=\"bottom\" class=\"wgrow wggridheader\" id=\"{0}r0\">", grid.ID); for (int ii = 0; ii < sortedColumns.Length; ii++) { Column column = grid.MasterTable.Columns[sortedColumns[ii]]; ColumnHeader addcolumn = new ColumnHeader { m_Class = string.Format("{0} wgheadercell", column.CssClassTitle), m_Align = column.GridAlign, m_VAlign = VerticalPosition.bottom, m_GridRowCount = (-1), m_GridId = grid.ID }; if ((column.ColumnType == ColumnType.SystemColumn && ((WebGrid.SystemColumn)column).SystemColumnType == SystemColumn.SpacingColumn) == false) { if (column.WidthColumnHeaderTitle == Unit.Empty) { switch (column.ColumnType) { case ColumnType.SystemColumn: addcolumn.m_ColumnWidth = Unit.Percentage(1); break; case ColumnType.Decimal: case ColumnType.Number: { int columnwidth = column.Title.Length * 12; if (columnwidth > 200) { columnwidth = 200; } addcolumn.m_ColumnWidth = Unit.Pixel(columnwidth); } break; } // else // addcolumn.ColumnWidth = Unit.Pixel(100); } else { addcolumn.m_ColumnWidth = column.WidthColumnHeaderTitle; } grid[column.ColumnId].WidthColumnHeaderTitle = addcolumn.m_ColumnWidth; } addcolumn.RenderBeginTag(writer, column, null, "<th"); // writer.Write("<div class=\"wgheadercell\" id=\"{0}h{1}\">", grid.ID, column.ColumnId); if (column.UseAllRows && (grid.SelectableRows || grid.RowHighLight != Color.Empty)) { grid.RowHighLight = Color.Empty; grid.SelectableRows = false; } if (column.IsInDataSource && column.Sortable) { string[] arrayParams = new string[1]; if (grid.MasterTable.DataSource != null) { arrayParams[0] = column.ColumnId; } else /*if (column.ColumnType == ColumnType.Foreignkey || !string.IsNullOrEmpty(grid.Sql))*/ { arrayParams[0] = Interface.BuildTableElement(true, column.m_Table.DataSourceId, column.ColumnId); } /*else * { * Foreignkey fk = (Foreignkey) column; * arrayParams[0] = * Foreignkey.BuildDisplayTextSql( * string.Format(" [_pk{0}_{1}].", sortedColumns[ii], fk.DataSourceId), * fk.ValueColumn, string.Empty, * true, fk.Table); * if (fk.Table.DataSource != null) * arrayParams[0] = fk.ColumnId; * }*/ string columnHeaderText = column.HeaderText; if (string.IsNullOrEmpty(column.ToolTipGridHeaderText) == false) { columnHeaderText = Tooltip.Add(columnHeaderText, column.ToolTipGridHeaderText); } StringBuilder hyperlink; if (!grid.AllowSort) { hyperlink = new StringBuilder( String.Format("<span class=\"{1}\">{0}</span>", columnHeaderText, null)); } else { string sortimage = string.Empty; // Up/down images if (grid.DisplaySortIcons && grid.MasterTable.OrderBySortList[arrayParams[0]] != null) { /*StringBuilder img = new StringBuilder("sort-"); * if (grid.MasterTable.OrderBySortList[arrayParams[0]].m_Desc) * img.Append("down"); * else * img.Append("up"); * if (grid.MasterTable.OrderBySortList[arrayParams[0]].m_DisplayIndex != 0) * img.Append("2"); * img.Append(".gif"); * * string sort = * string.Format(" <img style=\" border:0px\" alt=\"{0}\" src=\"{1}{2}\" />", * grid.GetSystemMessage("SortIcon"), grid.ImagePath, img);*/ if (grid.MasterTable.OrderBySortList[arrayParams[0]].m_Desc) { sortimage = string.Format( @"<span title=""{0}"" style=""float:left"" class=""ui-icon ui-icon-triangle-1-s""/>", grid.GetSystemMessage("SortIcon")); } else { sortimage = string.Format( @"<span title=""{0}"" style=""float:left"" class=""ui-icon ui-icon-triangle-1-n""/>", grid.GetSystemMessage("SortIcon")); } } hyperlink = new StringBuilder("<table cellspacing=\"0\" cellpadding=\"0\"><tr><td>"); hyperlink.Append(new StringBuilder( Buttons.Anchor(grid, columnHeaderText, "ColumnHeaderClick", arrayParams, null, null, null, null, false))); hyperlink.Append("</td><td>"); hyperlink.Append(sortimage); hyperlink.Append("</td></tr></table>"); } if (grid.NonBreakingHeaders) { hyperlink.Insert(0, "<span class=\"wgnowrap\">"); hyperlink.Append("</span>"); } writer.Write(hyperlink.ToString()); } else { string css = string.Empty; if (grid.NonBreakingHeaders) { css += " wgnowrap"; } writer.Write("<span class=\"{0}\">{1}</span>", css, column.HeaderText); } addcolumn.RenderEndTag(writer, "</th>"); } writer.Write("</tr>"); // FINISH CREATE HEADING } if (grid.RecordsPerRow == 1) { writer.Write("</thead>"); } bool tree = !string.IsNullOrEmpty(grid.TreeParentId); writer.Write(grid.BeforeRowsEvent()); if (grid.Trace.IsTracing) { grid.Trace.Trace("Started Rendering Rows ({0})", grid.ID); } writer.Write("<tbody>"); CreateRows(grid, tree, null, 0, writer, sortedColumns, 0); if (grid.RecordsPerRow == 1) { CreateTotalSummary(grid, writer, sortedColumns); } if (grid.Trace.IsTracing) { grid.Trace.Trace("Stopped Rendering Rows ({0}).", grid.ID); } writer.Write(grid.AfterRowsEvent()); writer.Write("</tbody>"); if (!string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarGridBottom))) { writer.Write("<tfoot>"); if (grid.IsUsingJQueryUICSSFramework) { writer.Write("<tr class=\"ui-widget-header wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); } else { writer.Write("<tr class=\"wgrow\"><td colspan=\"{0}\" class=\"wgtoolbargrid\">", sortedColumns.Length); } CreateGridToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarGridBottom), writer, grid); writer.Write("</td></tr></tfoot>"); } writer.Write("</table>"); if (grid.Page != null) { if (grid.EnableCallBack) { writer.Write("<input type=\"hidden\" id=\"{0}checkboxes\" name=\"{0}checkboxes\" value=\"{1}\" />", grid.ClientID, m_Checkboxlist.ToString()); } else { grid.Page.ClientScript.RegisterHiddenField(string.Format("{0}checkboxes", grid.ClientID), m_Checkboxlist.ToString()); } } }
internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell) { if (cell == null) return; switch (SystemColumnType) { case Enums.SystemColumn.PagerColumn: if (Grid.RecordCount > Grid.PageSize) return; cell.Row.m_Table.m_Grid.PagerSettings.SliderOperation = System.Web.UI.WebControls.Orientation.Vertical; writer.Write(cell.Row.m_Table.m_Grid.PagerSettings.GetPager); cell.Row.m_Table.m_Grid.PagerSettings.PagerType = PagerType.None; break; case Enums.SystemColumn.SelectColumn: writer.Write( SelectableRows.GetItemCheckbox(Grid, cell.Row.PrimaryKeyValues, string.Empty, Grid.ColorToHtml(Grid.SelectRowColor))); break; case Enums.SystemColumn.DeleteColumn: if (cell.Row.AllowDelete == false) { Visibility = Visibility.None; Title = null; } else { string strConfirmDelete = Grid.GetSystemMessage("ConfirmDelete"); if (Html == null) writer.Write(Buttons.Anchor(Grid, " ", "RecordDeleteClick", new[] { cell.Row.PrimaryKeyValues }, strConfirmDelete, Grid.GetSystemMessage("DeleteRow"), "ui-icon ui-icon-trash", null, false)); else writer.Write( Buttons.TextButtonControl(Grid, Html, "RecordDeleteClick", new[] { cell.Row.PrimaryKeyValues }, null, strConfirmDelete)); } break; case Enums.SystemColumn.SpacingColumn: WidthColumnHeaderTitle = System.Web.UI.WebControls.Unit.Empty; writer.Write(" "); break; case Enums.SystemColumn.CopyColumn: if (cell.Row.AllowCopy == false) { Visibility = Visibility.None; Title = null; } else { const string strConfirmCopy = null; if (Html == null) writer.Write( Buttons.Anchor(Grid, " ", "RecordCopyClick", new[] { string.Empty, cell.Row.PrimaryKeyValues }, strConfirmCopy, Grid.GetSystemMessage("CopyRow"), "ui-icon ui-icon-copy", null, false)); else writer.Write( Buttons.TextButtonControl(Grid, Html, "RecordCopyClick", new[] { string.Empty, cell.Row.PrimaryKeyValues }, null, strConfirmCopy)); } break; case Enums.SystemColumn.NewRecordColumn: if (Grid.AllowNew == false) { Visibility = Visibility.None; Title = null; } else { if (Html == null) writer.Write( Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("NewRecord"), "NewRecordClick", new string[] { }, Grid.GetSystemMessageClass("NewRecord", "wgnewrecord"))); else writer.Write( Buttons.TextButtonControl(Grid, Html, "NewRecordClick", new string[] { }, Grid.GetSystemMessageClass("NewRecord", "wgnewrecord"))); } break; case Enums.SystemColumn.UpdateGridRecordsColumn: if (Grid.AllowUpdate == false) { Visibility = Visibility.None; Title = null; } else { if (Html == null) writer.Write( Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("UpdateRows"), "UpdateRowsClick", new string[] { }, Grid.GetSystemMessageClass("UpdateRows", "wgUpdateRows"))); else writer.Write( Buttons.TextButtonControl(Grid, Html, "UpdateRowsClick", new string[] { }, Grid.GetSystemMessageClass("UpdateRows", "wgUpdateRows"))); } break; case Enums.SystemColumn.UpdateGridRecordColumn: if (Grid.AllowUpdate == false) { Visibility = Visibility.None; Title = null; } else { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); System.Web.UI.HtmlTextWriter textwriter = new System.Web.UI.HtmlTextWriter(sw); if (Html == null) textwriter.Write(Buttons.TextButtonControl(Grid, Grid.GetSystemMessage("UpdateRow"), "UpdateRowClick", new[] { cell.Row.PrimaryKeyValues }, Grid.GetSystemMessageClass("UpdateRow", "wgUpdateRow"))); else textwriter.Write(Buttons.TextButtonControl(Grid, Html, "UpdateRowClick", new[] { cell.Row.PrimaryKeyValues }, Grid.GetSystemMessageClass("UpdateRow", "wgUpdateRow"))); writer.Write(sb); } break; } // base.RenderLabelView(writer,cell); RenderGrid(null, writer, cell); }
internal static void CreateTitle(Grid grid, DisplayView mode, WebGridHtmlWriter writer, int[] sortedColumnID, int editMaxCells, string tagstyle) { string strclass = "wgtitlegrid"; if (mode == DisplayView.Detail) strclass = "wgtitledetail"; bool isHeader = GetIsHeader(grid); if (!isHeader) return; if (grid.IsUsingJQueryUICSSFramework && grid.DisplayView == DisplayView.Detail) writer.Write("<tr class=\"ui-widget-header wgrow\">"); else writer.Write("<tr class=\"wgrow\">"); ColumnHeader header = new ColumnHeader { m_ColumnSpan =(mode == DisplayView.Grid ? sortedColumnID.Length : editMaxCells), m_Class = string.Format("{0} wgheadercell", strclass) }; header.RenderBeginTag(writer, null, null, string.Format("<{0}", tagstyle)); writer.Write(grid.Title); header.RenderEndTag(writer, string.Format("</{0}>", tagstyle)); writer.Write("</tr>"); }
private static void StartNewRow(Row row, string style, WebGridHtmlWriter writer) { Grid grid = row.m_Table.m_Grid; StringBuilder js = new StringBuilder(string.Empty); string onmouseover = string.Empty; string onmouseout = string.Empty; if (grid.RowHighLight != Color.Empty) { row.RowHighLight = grid.RowHighLight; if (row.RowHighLight != Color.Empty) { onmouseover += string.Format("wgrowhighlight(this, 'over', '{0}');", Grid.ColorToHtml(grid.RowHighLight)); onmouseout += "wgrowhighlight(this,'','');"; } } #region Client Row Events if (!string.IsNullOrEmpty(grid.OnClientRowClick)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowClick }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowclick", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); js.AppendFormat(@" onclick=""{0}(this,{1});return false"" ", grid.OnClientRowClick, jsonId); } if (!string.IsNullOrEmpty(grid.OnClientRowDblClick)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowDblClick }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowdblclick", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); js.AppendFormat(@" ondblclick=""{0}(this,{1});return false"" ", grid.OnClientRowDblClick, jsonId); } if (!string.IsNullOrEmpty(grid.OnClientRowMouseOut)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowMouseOut }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowmouseout", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); onmouseout += string.Format(@"{0}(this,{1}); ", grid.OnClientRowMouseOut, jsonId); } if (!string.IsNullOrEmpty(grid.OnClientRowMouseOver)) { ClientRowEventArgs ea = new ClientRowEventArgs { RowIndex = row.RowIndex, ClientEventType = ClientEventType.OnClientRowMouseOver }; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{1}rowmouseout", grid.ID, row.RowIndex).Replace("-", "A"); grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); onmouseover += string.Format(@"{0}(this,{1}); ", grid.OnClientRowMouseOver, jsonId); } if (!string.IsNullOrEmpty(onmouseover)) { js.AppendFormat(@" onmouseover=""{0}""", onmouseover); } if (!string.IsNullOrEmpty(onmouseout)) { js.AppendFormat(@" onmouseout=""{0}""", onmouseout); } #endregion if (row.PreRowHtml != null) { if (row.PreRowHtml is string) { writer.Write((string)row.PreRowHtml); } else if (row.PreRowHtml is Control) { writer.Write((Control)row.PreRowHtml); } } if (grid.RecordsPerRow > 1) { grid.m_RowsAdded++; writer.Write("<tr class=\"wgrow\" id=\"{0}r{1}\" {2} class=\"{3} {4}\">", row.m_Table.m_Grid.ID, grid.m_RowsAdded, js.ToString(), style, row.CssClass); } else { writer.Write("<tr class=\"wgrow\" id=\"{0}r{1}\" {2} class=\"{3} {4}\">", row.m_Table.m_Grid.ID, row.RowIndex, js.ToString(), style, row.CssClass); } }
internal override void RenderEditView(WebGridHtmlWriter writer,RowCell cell) { if (AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false) || !Grid.GotHttpContext) { RenderLabelView(writer,cell); return; } StringBuilder s = new StringBuilder(string.Empty); StringBuilder javascript = new StringBuilder(string.Empty); s.Append(FileSource(false,cell)); StringBuilder onblur = new StringBuilder(" onblur=\""); if (Grid.InputHighLight != Color.Empty) { javascript.AppendFormat( " onfocus=\"accessKey = style.backgroundColor;style.backgroundColor='{0}';\"", Grid.ColorToHtml(Grid.InputHighLight)); onblur.Append("style.backgroundColor=accessKey;"); } if (Grid.ColumnChangedColour != Color.Empty) { onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour)); } onblur.Append("\""); javascript.Append(onblur); s.AppendFormat("<br/><input {0} {2} type=\"file\" class=\"wgeditfield\" name=\"{1}\" id=\"{1}\"/>", javascript, cell.CellClientId, Attributes); if (AllowEmpty && Required == false && Grid.InternalId != null && ((cell.Value != null) || (FileNameColumn != null && cell.Value != null))) s.AppendFormat( "<br/><input class=\"wglinkfield\" name=\"{0}_delete\" id=\"{0}_delete\" value=\"TRUE\" type=\"checkbox\" /><label class=\"wgnowrap wglabel\" id=\"label_{0}\" for=\"{0}_delete\">{1}</label>", cell.CellClientId, Grid.GetSystemMessage("RemoveImage")); if (Grid.FindForm != null) { if (Grid.EnableCallBack) { if (Grid.FindForm.Enctype.Equals("multipart/form-data", StringComparison.OrdinalIgnoreCase) == false) Manager.AddScriptForClientSideEval(string.Format("document.getElementById(\"{0}\").encoding = \"multipart/form-data\";", Grid.FindForm.ClientID)); } else Grid.FindForm.Enctype = "multipart/form-data"; } else throw new GridException( string.Format("HtmlForm is not found for grid '{0}' and column '{1}'", Grid.ID, ColumnId)); if (string.IsNullOrEmpty(ToolTipInput) == false) s = new StringBuilder(Tooltip.Add(s.ToString(), ToolTipInput)); EditHtml(s.ToString(), writer,cell); }
private void CreateRows(Grid grid, bool tree, string parentValue, int level, WebGridHtmlWriter writer, int[] sortedColumnID, int numberOfRowsDrawn) { // CREATE ROWS int styleRows = 0; int rows = 1; bool isNewRecordsPerRow = false; if (grid.RecordsPerRow > 1 && grid.MasterTable.Rows.Count > 0) { if (grid.IsUsingJQueryUICSSFramework) { writer.Write( "<tr><td width=\"100%\" colspan=\"{0}\"><table class=\"wgrecordsperrow\"><tr class=\"ui-widget\">", sortedColumnID.Length); } else { writer.Write( "<tr><td width=\"100%\" colspan=\"{0}\"><table class=\"wgrecordsperrow\"><tr>", sortedColumnID.Length); } } ColumnCollection columns = grid.MasterTable.Columns; for (int i = 0; i < grid.MasterTable.Rows.Count; i++) { Row currentRow = grid.MasterTable.Rows[i]; if (!grid.BeforeRowRenderEvent(ref currentRow, ref columns)) { continue; } grid.MasterTable.Columns = columns; grid.m_RowsAdded++; currentRow.RowIndex = grid.m_RowsAdded; if (grid.RecordsPerRow > 1) { if (isNewRecordsPerRow) { if (grid.IsUsingJQueryUICSSFramework) { writer.Write("<tr class=\"ui-widget\" id=\"{0}r{1}\">", grid.ID, grid.m_RowsAdded); } else { writer.Write("<tr id=\"{0}r{1}\">", grid.ID, grid.m_RowsAdded); } isNewRecordsPerRow = false; } if (grid.IsUsingJQueryUICSSFramework) { writer.Write( "<td style=\"height: 100%; vertical-align: top\" width=\"{0}%\"><table class=\"wgrecordsperrow\">", (100 / grid.RecordsPerRow)); } else { writer.Write( "<td style=\"height: 100%; vertical-align: top\" width=\"{0}%\"><table class=\"wgrecordsperrow\">", (100 / grid.RecordsPerRow)); } } if (tree) { string treeValue = null; if (currentRow[grid.TreeParentId].Value != null) { treeValue = currentRow[grid.TreeParentId].Value.ToString(); } if (treeValue != parentValue || Grid.EMPTYSTRINGCONSTANT.Equals(currentRow.PrimaryKeyValues)) { continue; } } numberOfRowsDrawn++; styleRows++; string style = "wgrow"; if (styleRows > 1) { style = "wgalternativerow wgrow"; } if (grid.IsUsingJQueryUICSSFramework) { style = "ui-widget " + style; } if (styleRows >= 2) { styleRows = 0; } // Past this page, no more to draw if (tree && grid.PageIndex != 0 && grid.PageSize != 0 && numberOfRowsDrawn > (grid.PageIndex) * grid.PageSize) { if (grid.Trace.IsTracing) { grid.Trace.Trace("Did break row writing. Reason: Past this page, no more to draw."); } break; } // For tree, don't draw previous pages, but still run recursive functions. if (tree == false || grid.PageIndex == 0 || grid.PageSize == 0 || numberOfRowsDrawn > (grid.PageIndex - 1) * grid.PageSize) { int rowsInThisRecord = 0; for (int ii = 0; ii < sortedColumnID.Length; ii++) // Create cells... { Column column = columns[sortedColumnID[ii]]; RowCell rowcell = currentRow[column.ColumnId]; if (ii == 0 || column.NewRowInGrid) { if (rowsInThisRecord > 0) { writer.Write("</tr>"); } rowsInThisRecord++; StartNewRow(grid.MasterTable[i], style, writer); } // Shall this column span over all the rows? if (i != 0 && column.UseAllRows && grid.RecordsPerRow == 1) { continue; } // Automatically set columnSpan if 'NewRowInGrid' property is enabled. if (ii < sortedColumnID.Length - 1 && columns[sortedColumnID[ii + 1]].NewRowInGrid) { rowcell.InternalCellSpan = sortedColumnID.Length - ii; } column.m_TreeLevel = level; if (columns[sortedColumnID[ii]].UseAllRows) { column.Rowspan = grid.RecordsPerRow == 1 ? grid.MasterTable.Rows.Count : 1; } column.Render(writer, rowcell); if (column.ColumnType == ColumnType.SystemColumn && ((WebGrid.SystemColumn)column).SystemColumnType == SystemColumn.SelectColumn) { m_Checkboxlist.AppendFormat("{0}!", rowcell.Row.PrimaryKeyValues); } if (sortedColumnID.Length - 1 == ii || (sortedColumnID.Length + 1 < ii && columns[sortedColumnID[ii + 1]].NewRowInGrid)) { EndRow(grid.MasterTable[i], writer); } } } if (tree) { CreateRows(grid, true, currentRow.PrimaryKeyValues, level + 1, writer, sortedColumnID, numberOfRowsDrawn); } if (grid.RecordsPerRow <= 1) { continue; } writer.Write("</table></td>"); if ((i + 1) == grid.MasterTable.Rows.Count && (grid.MasterTable.Rows.Count < grid.RecordsPerRow || rows < grid.RecordsPerRow)) { while (rows < grid.RecordsPerRow) { writer.Write("<td height=\"100%\" width=\"{0}%\"></td>", (100 / grid.RecordsPerRow)); rows++; } } if (rows == grid.RecordsPerRow) { writer.Write("</tr>"); rows = 0; isNewRecordsPerRow = true; } rows++; } if (grid.RecordsPerRow <= 1 || grid.MasterTable.Rows.Count <= 0) { return; } if (rows > 1) { writer.Write("</tr>"); } writer.Write("</table></td></tr>"); }
internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell) { LabelHtml("many-to-many column is not supported in grid view.", writer, cell); }
private static void CreateDetailToolbar(string toolbar, WebGridHtmlWriter writer, Grid grid, bool editablecolumns) { if (toolbar.IndexOf("[UPDATE]", StringComparison.OrdinalIgnoreCase) > -1) { if (editablecolumns) { string updatemessage = grid.StayInDetail || grid.m_IsGridInsideGrid ? "Update" : "UpdateClose"; string status = string.Empty; if (grid.m_IsOneToOneRelationGrid && grid.m_IsOneToOneRelationNewRecord) status = "!new"; if (grid.m_IsOneToOneRelationGrid && grid.m_IsOneToOneRelationNewRecord == false) status = "!update"; toolbar = toolbar.Replace("[UPDATE]", ( Buttons.TextButtonControl(grid, grid.GetSystemMessage(updatemessage), "RecordUpdateClick", new[] { string.Format("{0}!{1}{2}", grid.InternalId, grid.m_IsCopyClick, status) }, grid.GetSystemMessageClass(updatemessage, "wgupdaterecord"), null, grid.ID + "_wgupdaterecord"))); } else toolbar = toolbar.Replace("[UPDATE]", string.Empty); } if (toolbar.IndexOf("[CLOSEWINDOW]", StringComparison.OrdinalIgnoreCase) > -1) { if ((grid.MasterWebGrid != null && !grid.m_IsGridInsideGrid) || (grid.ActiveMenuSlaveGrid == null || (grid.m_HasGridInsideGrid && grid.ActiveMenuSlaveGrid == null)) && (grid.AllowCancel) || (grid.m_IsGridInsideGrid && grid.AllowCancel)) { if ((grid.MasterWebGrid != null && grid.m_IsGridInsideGrid == false) && grid.AllowCancel == false) grid.m_IsOneToOneRelationGrid = true; toolbar = toolbar.Replace("[CLOSEWINDOW]", ( Buttons.TextButtonControl(grid, grid.GetSystemMessage("CloseWindow"), "RecordCancelClick", new[] { string.Format("{0}!{1}", grid.InternalId, grid. m_IsOneToOneRelationGrid) } , grid.GetSystemMessageClass("CloseWindow", "wgclosewindow")))); } else { toolbar = toolbar.Replace("[CLOSEWINDOW]", string.Empty); } } if (string.IsNullOrEmpty(toolbar) == false) writer.Write(toolbar); }
/* public static void Render(string content, string cssclass, HtmlTextWriter writer) * { * ColumnCell td = new ColumnCell {m_Class = cssclass}; * td.RenderBeginTag(writer); * writer.Write(content); * td.RenderEndTag(writer); * } */ public void RenderBeginTag(WebGridHtmlWriter writer, Column column, RowCell cell, string tagtype) { StringBuilder tdStart = new StringBuilder(tagtype); string name = ""; if (column != null) { name = column.ColumnId; } if (m_Align != HorizontalPosition.Undefined) { tdStart.AppendFormat(" align=\"{0}\"", m_Align.ToString().ToLowerInvariant()); } if (m_VAlign != VerticalPosition.undefined) { tdStart.AppendFormat(" valign=\"{0}\"", m_VAlign.ToString().ToLowerInvariant()); } if (string.IsNullOrEmpty(m_Class) == false) { tdStart.AppendFormat(" class=\"{0}\" ", m_Class); } if (m_GridRowCount == -1) { if (m_ColumnWidth != Unit.Empty) { tdStart.AppendFormat(" style=\"width: {0}\"", m_ColumnWidth); } if (string.IsNullOrEmpty(name) == false) { tdStart.AppendFormat(" id=\"{0}{1}r0\"", m_GridId, name); } } else if (string.IsNullOrEmpty(name) == false && m_GridRowCount > 0) { tdStart.AppendFormat(" id=\"{0}{1}r{2}\"", m_GridId, name, m_GridRowCount); } else if (string.IsNullOrEmpty(name) == false) { tdStart.AppendFormat(" id=\"{0}{1}\"", name, m_GridRowCount); } if (m_ColumnSpan > 1) { tdStart.AppendFormat(" colspan=\"{0}\"", m_ColumnSpan); } // if (m_RowSpan > 1) tdStart.AppendFormat(" rowspan=\"{0}\"", m_RowSpan); if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellClick)) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) { ea.Value = cell.Value; } ea.ClientEventType = ClientEventType.OnClientColumnClick; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}", m_GridId, name, m_GridRowCount).Replace("-", "A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@" onclick=""{0}(this,{1});return false"" ", writer.Grid.OnClientCellClick, jsonId); } if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellDblClick)) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) { ea.Value = cell.Value; } ea.ClientEventType = ClientEventType.OnClientColumnDblClick; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}", m_GridId, name, m_GridRowCount).Replace("-", "A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@" ondblclick=""{0}(this,{1});return false"" ", writer.Grid.OnClientCellDblClick, jsonId); } if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOver)) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) { ea.Value = cell.Value; } ea.ClientEventType = ClientEventType.OnClientColumnMouseOver; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}mouseover", m_GridId, name, m_GridRowCount).Replace("-", "A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@"onmouseover=""{0}(this,{1});return false""", writer.Grid.OnClientCellMouseOver, jsonId); } if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOut)) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) { ea.Value = cell.Value; } ea.ClientEventType = ClientEventType.OnClientColumnMouseOut; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}mouseout", m_GridId, name, m_GridRowCount).Replace("-", "A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@"onmouseout=""{0}(this,{1});return false""", writer.Grid.OnClientCellMouseOut, jsonId); } tdStart.Append(">"); writer.Write(tdStart); }
internal static void RenderDetail(ref Grid grid, ref WebGridHtmlWriter writer) { string width = grid.Width.IsEmpty == false ? grid.Width.ToString() : "100%"; /* cellpadding and cellspacing are fixed because CSS does not support similar behavior*/ if (grid.IsUsingJQueryUICSSFramework) writer.Write( //ui-helper-reset "<table width=\"{0}\" class=\"ui-widget-content wgmaindetail\" cellspacing=\"0\" cellpadding=\"0\">", width); else writer.Write("<table width=\"{0}\" class=\"wgmaindetail\" cellspacing=\"0\" cellpadding=\"0\">", width); int[] sortedColumns = grid.VisibleSortedColumns; int columnWidth = -1; int allRowsColumns = 0; int ant = 0; bool firstvisiblecolumn = true; bool editablecolumns = grid.m_Forceeditablecolumns; for (int i = 0; i < sortedColumns.Length; i++) { ant += 2; // if( Grid.BasicDetailLayout ) // ant--; if (grid.DisplayRequiredColumn) ant++; if (ant > columnWidth) columnWidth = ant; Column c = grid.MasterTable.Columns[sortedColumns[i]]; if (c.UseAllRows) allRowsColumns++; if (c.IsVisible == false) continue; if (editablecolumns == false && c.AllowEdit) editablecolumns = true; if (firstvisiblecolumn) { firstvisiblecolumn = false; continue; } if (c.NewRowInDetail) ant = 0; } // Create head CreateTitle(grid, DisplayView.Detail, writer, sortedColumns, columnWidth,"td"); if ((grid.CollapseIfSlaveGrid && grid.ActiveMenuSlaveGrid != null) || grid.CollapsedGrid) { writer.Write("</table>"); return; } // Create toolbar if (string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarDetailTop)) == false) { if( grid.IsUsingJQueryUICSSFramework) writer.Write( "<tr class=\"ui-widget-header wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); else writer.Write( "<tr class=\"wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); CreateDetailToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarDetailTop), writer, grid, editablecolumns); writer.Write("</td></tr>"); } int antcols = 0; if (allRowsColumns > 0) writer.Write( "<tr><td colspan=\"{0}\"><table class=\"wgrowspan\"><tr valign=\"top\"><td><table class=\"wgrowspan\">", columnWidth); grid.MasterTable.Rows[0].RowIndex = -1; for (int i = 0; i < sortedColumns.Length; i++) { Column column = grid.MasterTable.Rows[0] != null ? grid.MasterTable.Columns[sortedColumns[i]] : grid.MasterTable.Columns[sortedColumns[i]]; if (column.UseAllRows && i > 0) writer.Write("</table></td><td><table class=\"wgrowspan\">"); if (i == 0 || (i < sortedColumns.Length && column.NewRowInDetail)) { antcols = 0; writer.Write("<tr class=\"wgrow\">"); } if (!column.HideDetailTitle) { ColumnHeader columnName = new ColumnHeader { m_VAlign = column.EditVAlign, m_Align = column.EditAlignTitle, m_ColumnWidth = column.WidthColumnTitle, m_Class = string.Format("{0} wgdetailheader", column.CssClassTitle), m_GridRowCount = (-1), m_GridId = grid.ID }; if (columnName.m_ColumnWidth == Unit.Empty) { int columnwidth = column.Title.Length * 12; if (columnwidth > 140) columnwidth = 140; columnName.m_ColumnWidth = Unit.Pixel(columnwidth); } columnName.RenderBeginTag(writer, column, null,"<td"); if (string.IsNullOrEmpty(column.ToolTipEditTitle)) writer.Write(column.Title); else writer.Write(Tooltip.Add(column.Title, column.ToolTipEditTitle)); antcols++; if (grid.BasicDetailLayout == false) columnName.RenderEndTag(writer,"</td>"); if (grid.DisplayRequiredColumn) { antcols++; ColumnHeader requiredColumn = new ColumnHeader { m_Class = string.Format("wgrequiredcolumn {0}", column.CssClassTitle), m_ColumnWidth = Unit.Pixel(1), m_VAlign = (column.HeightEditableColumn.IsEmpty ? column.EditVAlign : VerticalPosition.top) }; requiredColumn.RenderBeginTag(writer, column, null,"<td"); if (column.Required && column.AllowEdit) writer.Write(@"<span title=""{0}"" class=""ui-icon ui-icon-info""/>", grid.GetSystemMessage("Required")); else writer.Write(" "); requiredColumn.RenderEndTag(writer, "</td>"); } } antcols++; if ((i == sortedColumns.Length - 1 || (i + 1 < sortedColumns.Length && grid[sortedColumns[i + 1]].NewRowInDetail)) && antcols < columnWidth) grid.Rows[0][column.ColumnId].InternalCellSpan += columnWidth - antcols; // column.Row = grid.MasterTable.Rows[0]; column.Render(writer, grid.Rows[0][column.ColumnId]); if (i == sortedColumns.Length - 1 || (i + 1 < sortedColumns.Length && grid[sortedColumns[i + 1]].NewRowInDetail)) { writer.Write("</tr>"); } if (column.UseAllRows) if (i + 1 < sortedColumns.Length) writer.Write("</table></td><td><table class=\"wgrowspan\">"); else writer.Write("</table>"); else if (allRowsColumns > 0 && i + 1 == sortedColumns.Length) writer.Write("</table>"); } if (allRowsColumns > 0) writer.Write("</td></tr></table></td></tr>"); // Create tail if (string.IsNullOrEmpty(grid.GetToolbarHtml(ToolbarType.ToolbarDetailBottom)) == false) { if(grid.IsUsingJQueryUICSSFramework) writer.Write( "<tr class=\"ui-widget-header wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); else writer.Write( "<tr class=\"wgrow\"><td class=\"wgtoolbardetail\" colspan=\"{0}\">", columnWidth); CreateDetailToolbar(grid.GetToolbarHtml(ToolbarType.ToolbarDetailBottom), writer, grid, editablecolumns); writer.Write("</td></tr>"); } writer.Write("</table>"); }
internal static void CreateFilterByColumns(Grid grid, WebGridHtmlWriter writer, int[] sortedColumnID) { grid.m_RowsAdded++; writer.Write( grid.IsUsingJQueryUICSSFramework ? "<tr class=\"ui-widget wgrow\" id=\"{0}r{1}\">" : "<tr class=\"wgrow\" id=\"{0}r{1}\">", grid.ID, grid.m_RowsAdded); for (int ii = 0; ii < sortedColumnID.Length; ii++) { Column column = grid.MasterTable.Columns[sortedColumnID[ii]]; if (column.FilterByColumnCollection.Count == 0) { string columnstyle = string.Empty; string columnId = string.Format(" id=\"{0}{1}r{2}\"", grid.ID, column.ColumnId, grid.m_RowsAdded); if (grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle != Unit.Empty) { columnstyle = string.Format("style=\"width: {0};\"", grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle); } writer.Write("<th {0} {1}> </th>", columnstyle, columnId); continue; } ColumnHeader addcolumn = new ColumnHeader { m_Class = string.Format("{0} wggridcell", column.CssClassTitle), m_Align = column.GridAlign, m_VAlign = VerticalPosition.bottom, m_ColumnWidth = grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle, m_GridRowCount = grid.m_RowsAdded, m_GridId = grid.ID }; addcolumn.RenderBeginTag(writer, column, null, "<th"); string selectedValue = null; if (Grid.GotHttpContext && HttpContext.Current.Request.Form[string.Format("ddl{0}", column.ClientHeaderId)] != null) { selectedValue = HttpUtility.HtmlEncode( HttpContext.Current.Request.Form[string.Format("ddl{0}", column.ClientHeaderId)]); grid.State(string.Format("ddl{0}", column.ClientHeaderId), selectedValue); } else if (grid.GetState(string.Format("ddl{0}", column.ClientHeaderId)) != null) { selectedValue = grid.GetState(string.Format("ddl{0}", column.ClientHeaderId)) as string; } bool isdate = false; if (grid.MasterTable.Columns[column.ColumnId].ColumnType == ColumnType.DateTime) { isdate = true; } string eventScript = string.Empty; if (grid.Page != null) { string link = grid.EnableCallBack && !column.ForcePostBack ? Asynchronous.GetCallbackEventReference(grid, string.Format("ElementPostBack!ddl{0}", column.ColumnId), false, string.Empty, string.Empty) : grid.Page.ClientScript.GetPostBackEventReference(grid, string.Format("ElementPostBack!ddl{0}", column.ColumnId)); eventScript = string.Format(" onchange=\"{0}\" ", link); } string style = grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle != Unit.Empty ? "class=\"wgeditfield wgselectbox \"" : " class=\"wgeditfield wgselectbox \" "; if (!isdate) { StringBuilder dropdownbox = new StringBuilder("<select "); dropdownbox.AppendFormat("{0} name=\"ddl{1}\" id=\"ddl{1}\" {2}><option value=\"\" selected=\"selected\">{3}</option>", style, column.ClientHeaderId, eventScript, column.Grid.GetSystemMessage("EmptySearchFilter")); if (grid.Scripts == null || !grid.Scripts.DisableSelectMenu) { Grid.AddClientScript(writer, string.Format("$(document).ready(function() {{$('#ddl{0}').selectmenu({{maxHeight: {2},style:'dropdown',width: {1}}});}});", column.ClientHeaderId, column.WidthColumnHeaderTitle.Value, 400)); } int i = 0; while (i < column.FilterByColumnCollection.Count) { string _value = HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]); string _title = HttpUtility.HtmlEncode(column.FilterByColumnCollection.GetKey(i)); if (selectedValue != null && selectedValue == _value) { dropdownbox.AppendFormat("<option selected=\"selected\" value=\"{0}\">{1}</option>", HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]), _title); } else { dropdownbox.AppendFormat("<option value=\"{0}\">{1}</option>", HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]), _title); } i++; } writer.Write(dropdownbox); writer.Write("</select> "); } else { if (grid.DatabaseConnectionType != DataBaseConnectionType.SqlConnection) { throw new GridException( string.Format("'FilterByColumn' property for 'DateTime' ({0}) columns are only supported by 'SqlConnection' connection strings.", column.ColumnId)); } writer.Write("<span style=\"white-space: nowrap;vertical-align:middle;\">"); string filter = ((WebGrid.DateTime)grid.MasterTable.Columns[column.ColumnId]).SearchFilter; if (string.IsNullOrEmpty(filter)) { StringBuilder s = new StringBuilder(string.Empty); s.AppendFormat( "<a class=\"wglinkfield\" href=\"?DateFilter={0}\">{1}</a>", grid.MasterTable.Columns[column.ColumnId].ColumnId, column.Grid.GetSystemMessage("DateTimeSearch")); writer.Write(s); } else { StringBuilder s = new StringBuilder(string.Empty); s.AppendFormat( "<a class=\"wglinkfield\" href=\"#\" onclick=\"javascript:WGdisableDateTimeSearch('{0}');\";return false;\">{1}</a>", column.ColumnId, column.Grid.GetSystemMessage("DateTimeSearchReset")); writer.Write(s); } // From date writer.Write("</span>"); } addcolumn.RenderEndTag(writer, "</th>"); } writer.Write("</tr>"); }
private static void EndRow(Row row, WebGridHtmlWriter writer) { writer.Write("</tr>"); if (row.PostRowHtml != null) if (row.PostRowHtml is string) writer.Write((string) row.PostRowHtml); else if (row.PostRowHtml is Control) writer.Write((Control) row.PostRowHtml); }
internal void Render(WebGridHtmlWriter mywriter) { // MasterWebGrid is using SlaveGridMenu. if (((m_Grid.SystemMessage.CriticalCount == 0 && m_Grid.MasterGrid != null && m_Grid.MasterWebGrid != null && m_Grid.m_IsGridInsideGrid == false && m_Grid.MasterWebGrid.DisplaySlaveGridMenu && (m_Grid.MasterWebGrid.ActiveMenuSlaveGrid == null || m_Grid.MasterWebGrid.ActiveMenuSlaveGrid.ClientID != m_Grid.ClientID)) ) || (m_Grid.m_IsGridInsideGrid && m_Grid.MasterWebGrid != null && m_Grid.MasterWebGrid.m_HasRendered == false)) return; if (m_Grid.HideIfEmptyGrid && m_Grid.MasterTable.Rows.Count == 0 && m_Grid.SystemMessage.CriticalCount == 0 && !m_Grid.m_ActiveColumnFilter) { if (m_Grid.EmptyDataTemplate != null) mywriter.Write(m_Grid.EmptyDataTemplate); return; } m_Grid.m_HasRendered = true; if (m_Grid.Tag["wgcsslink"] != null) mywriter.Write(m_Grid.Tag.Get("wgcsslink")); if (m_Grid.Tag["wgscriptstyles"] != null) mywriter.Write(m_Grid.Tag.Get("wgscriptstyles")); if (m_Grid.PreGridTemplate != null) mywriter.Write(m_Grid.PreGridTemplate); string width = string.Empty; if (m_Grid.Width.IsEmpty == false) width = string.Format(" width=\"{0}\"", m_Grid.Width); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); System.Web.UI.HtmlTextWriter renderBeginTag = new System.Web.UI.HtmlTextWriter(sw); m_Grid.RenderBeginTag(renderBeginTag); string webAttributes = sb.ToString(); // Remove first tag which is always 'id=' webAttributes = webAttributes.Remove(0, webAttributes.IndexOf("id=")); // Clean up.. webAttributes = webAttributes.Remove(0, webAttributes.IndexOf(" ")); webAttributes = string.Format("<table{0}", webAttributes.Remove(webAttributes.Length - 1)); #region slavegrid menu bool systemMessagetriggered = false; if (m_Grid.DisplayView == DisplayView.Detail && m_Grid.DisplaySlaveGridMenu && m_Grid.SlaveGrid.Count > 0 && m_Grid.InternalId != null) { mywriter.Write("<!--WebGrid menu starts rendering -->\n"); mywriter.Write("{0} class=\"wgmenu\" {1} cellpadding=\"0\" cellspacing=\"0\" id=\"wgMenu_{2}\"><tr><td>", webAttributes, width, m_Grid.ClientID); if (m_Grid.SystemMessage.Count > 0) { mywriter.Write(m_Grid.SystemMessage.RenderSystemMessage); if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableBookmark) Grid.AddClientScript(mywriter, string.Format("bookmarkscroll.init();bookmarkscroll.scrollTo('wgSystemMessage_{0}')", m_Grid.ID)); mywriter.Write("</td></tr><tr><td>"); systemMessagetriggered = true; } /* cellpadding and cellspacing are fixed because CSS does not support similar behavior*/ mywriter.Write("<table class=\"wgmenunavigation\" cellpadding=\"0\" cellspacing=\"0\"><tr align=\"left\">"); bool createmenuspace = false; foreach (Grid slavegrid in m_Grid.SlaveGrid) { if (createmenuspace) mywriter.Write("<td class=\"wgmenuspacing\"></td>"); else createmenuspace = true; if (m_Grid.ActiveMenuSlaveGrid != slavegrid) { string colorstyle = null; if (Grid.MenuInactiveColor != Color.Empty) colorstyle = string.Format("style=\"background-color:{0}\"", Grid.ColorToHtml(Grid.MenuInactiveColor)); if (m_Grid.IsUsingJQueryUICSSFramework) mywriter.Write( "<td id=\"wgmenu_{0}_{1}\">{2}</td>", m_Grid.ClientID, slavegrid.ClientID, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); else mywriter.Write( "<td id=\"wgmenu_{0}_{1}\"><div class=\"wglefttab_off\"></div><div {2} class=\"wginactivemenu wgrighttab_off\">{3}</div></td>", m_Grid.ClientID, slavegrid.ClientID, colorstyle, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); } else { string colorstyle = null; if (Grid.MenuActiveColor != Color.Empty) colorstyle = string.Format("style=\"background-color:{0}\"", Grid.ColorToHtml(Grid.MenuActiveColor)); if (m_Grid.IsUsingJQueryUICSSFramework) mywriter.Write( "<td id=\"wgmenu_{0}_{1}\">{2}</td>", m_Grid.ClientID, slavegrid.ClientID, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); else mywriter.Write( "<td id=\"wgmenu_{0}_{1}\"><div class=\"wglefttab_on\"></div><div {2} class=\"wgactivemenu wgrighttab_on\">{3}</div></td>", m_Grid.ClientID, slavegrid.ClientID, colorstyle, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); } } mywriter.Write("</tr></table></td></tr></table><br/>"); mywriter.Write("<!--WebGrid menu finished rendering -->\n"); } #endregion if (m_Grid.SystemMessage.Count > 0 && systemMessagetriggered == false) { mywriter.Write(m_Grid.SystemMessage.RenderSystemMessage); if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableBookmark) Grid.AddClientScript(mywriter, string.Format("bookmarkscroll.init();bookmarkscroll.scrollTo('wgSystemMessage_{0}')", m_Grid.ID)); } mywriter.Write("<!--WebGrid grid starts rendering -->\n"); mywriter.Write("{0} {1} cellpadding=\"0\" class=\"wgmaingrid\" cellspacing=\"0\" id=\"wgContent_{2}\"><tr><td>", webAttributes, width, m_Grid.ID); ApplyAjaxLoader(mywriter); if (m_Grid.SystemMessage.CriticalCount == 0) { switch (m_Grid.DisplayView) { case DisplayView.Grid: if (m_Grid.AllowEditInGrid && m_Grid.PageIndex == 0 && m_Grid.Page != null) { if (m_Grid.EnableCallBack) mywriter.Write( "<input type=\"hidden\" id=\"{0}_where\" name=\"{0}_where\" value=\"{1}\" />", m_Grid.ClientID, HttpUtility.UrlEncode(m_Grid.FilterExpression, Encoding.Default)); else m_Grid.Page.ClientScript.RegisterHiddenField( string.Format("{0}_where", m_Grid.ClientID), HttpUtility.UrlEncode(m_Grid.FilterExpression, Encoding.Default)); } RenderGrid(ref m_Grid, ref mywriter); break; case DisplayView.Detail: RenderDetail(ref m_Grid, ref mywriter); break; } } mywriter.Write("</td></tr></table>"); mywriter.Write("<!--WebGrid grid finished rendering -->\n"); if (m_Grid.Page != null && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableWebGridClientObject)) { m_Grid.JsOnData.AppendLine(); m_Grid.JsOnData.Append(WebGridClientObject.GetGridObject(m_Grid)); } if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableContextMenu) { m_Grid.GetContextMenuHtml(mywriter); Grid.AddClientScript(mywriter, string.Format(contextscript, m_Grid.ID)); } if ( m_Grid.ClientNotifications != null && m_Grid.ClientNotifications.Count > 0 && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableClientNotification) ) { ClientNotification clientSettings = m_Grid.ClientNotification ?? Grid.DefaultClientNotification; if (clientSettings.HeaderText == null) clientSettings.HeaderText = m_Grid.Title; if (clientSettings.HeaderText == null) clientSettings.HeaderText = string.Empty; StringBuilder template = string.IsNullOrEmpty(clientSettings.Container) ? new StringBuilder( "$(document).ready( function() {{ $.jGrowl(\"{0}\", {{ header: '") : new StringBuilder( string.Format( "$(document).ready( function() {{ $('#{0}').jGrowl(\"{0}\", {{ header: '", clientSettings.Container)); template.Append(clientSettings.HeaderText.Replace("\"", "\\")); template.AppendFormat("', sticky: {0}", clientSettings.Sticky.ToString().ToLower()); template.AppendFormat(", life: {0}", clientSettings.LifeSpan); if (clientSettings.CloserTemplate != null) template.AppendFormat(", closerTemplate: '{0}'", clientSettings.CloserTemplate.Replace("\"", "\\")); template.Append(", closer: " + clientSettings.Closer.ToString().ToLower()); if (!string.IsNullOrEmpty(clientSettings.CssClass)) template.AppendFormat(", theme: '{0}'", clientSettings.CssClass); template.Append("}}); }});"); if (m_Grid.ClientNotifications.Count > 0) foreach (string arg in m_Grid.ClientNotifications) Grid.AddClientScript(mywriter, string.Format(template.ToString(), arg.Replace("\"", "\\"))); } if ( (m_Grid.Scripts == null || !m_Grid.Scripts.DisableInputMask) && m_Grid.MaskedColumns.Count > 0) { StringBuilder masks = new StringBuilder(); foreach (KeyValuePair<string,string> dictionary in m_Grid.MaskedColumns) { if (masks.Length > 3) masks.Append(", "); masks.AppendFormat("{0}:{{ mask: {1} }}", dictionary.Key, dictionary.Value); } string options; if (m_Grid.MaskedInput != null) options = string.Format("{{selectCharsOnFocus: {0},textAlign: {1},autoTab:{2}, attr: '{3}'}}", MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableSelectCharsOnFocus), MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableTextAlign), MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableAutoTab), m_Grid.MaskedInput.Attribute); else options = "{selectCharsOnFocus: true,textAlign: false,autoTab:false, attr: 'alt'}"; Grid.AddClientScript(mywriter, string.Format(meiomask, m_Grid.ID, masks, options)); } if (Anthem.Manager.IsCallBack && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableHoverButtons)) Grid.AddClientScript(mywriter, Grid.HoverButtonScript); if (m_Grid.JsOnData.Length > 2) mywriter.Write(@"<script type=""text/javascript"">{0}</script>", m_Grid.JsOnData.ToString()); mywriter.Close(); if (m_Grid.Trace.IsTracing) m_Grid.Trace.Trace("Finish Render();"); }
private void CreateRows(Grid grid, bool tree, string parentValue, int level, WebGridHtmlWriter writer, int[] sortedColumnID, int numberOfRowsDrawn) { // CREATE ROWS int styleRows = 0; int rows = 1; bool isNewRecordsPerRow = false; if (grid.RecordsPerRow > 1 && grid.MasterTable.Rows.Count > 0) if (grid.IsUsingJQueryUICSSFramework) writer.Write( "<tr><td width=\"100%\" colspan=\"{0}\"><table class=\"wgrecordsperrow\"><tr class=\"ui-widget\">", sortedColumnID.Length); else writer.Write( "<tr><td width=\"100%\" colspan=\"{0}\"><table class=\"wgrecordsperrow\"><tr>", sortedColumnID.Length); ColumnCollection columns = grid.MasterTable.Columns; for (int i = 0; i < grid.MasterTable.Rows.Count; i++) { Row currentRow = grid.MasterTable.Rows[i]; if (!grid.BeforeRowRenderEvent(ref currentRow, ref columns)) continue; grid.MasterTable.Columns = columns; grid.m_RowsAdded++; currentRow.RowIndex = grid.m_RowsAdded; if (grid.RecordsPerRow > 1) { if (isNewRecordsPerRow) { if (grid.IsUsingJQueryUICSSFramework) writer.Write("<tr class=\"ui-widget\" id=\"{0}r{1}\">", grid.ID, grid.m_RowsAdded); else writer.Write("<tr id=\"{0}r{1}\">", grid.ID, grid.m_RowsAdded); isNewRecordsPerRow = false; } if (grid.IsUsingJQueryUICSSFramework) writer.Write( "<td style=\"height: 100%; vertical-align: top\" width=\"{0}%\"><table class=\"wgrecordsperrow\">", (100/grid.RecordsPerRow)); else writer.Write( "<td style=\"height: 100%; vertical-align: top\" width=\"{0}%\"><table class=\"wgrecordsperrow\">", (100/grid.RecordsPerRow)); } if (tree) { string treeValue = null; if (currentRow[grid.TreeParentId].Value != null) treeValue = currentRow[grid.TreeParentId].Value.ToString(); if (treeValue != parentValue || Grid.EMPTYSTRINGCONSTANT.Equals(currentRow.PrimaryKeyValues)) continue; } numberOfRowsDrawn++; styleRows++; string style = "wgrow"; if (styleRows > 1) style = "wgalternativerow wgrow"; if (grid.IsUsingJQueryUICSSFramework) style = "ui-widget " + style; if (styleRows >= 2) styleRows = 0; // Past this page, no more to draw if (tree && grid.PageIndex != 0 && grid.PageSize != 0 && numberOfRowsDrawn > (grid.PageIndex)*grid.PageSize) { if (grid.Trace.IsTracing) grid.Trace.Trace("Did break row writing. Reason: Past this page, no more to draw."); break; } // For tree, don't draw previous pages, but still run recursive functions. if (tree == false || grid.PageIndex == 0 || grid.PageSize == 0 || numberOfRowsDrawn > (grid.PageIndex - 1)*grid.PageSize) { int rowsInThisRecord = 0; for (int ii = 0; ii < sortedColumnID.Length; ii++) // Create cells... { Column column = columns[sortedColumnID[ii]]; RowCell rowcell = currentRow[column.ColumnId]; if (ii == 0 || column.NewRowInGrid) { if (rowsInThisRecord > 0) writer.Write("</tr>"); rowsInThisRecord++; StartNewRow(grid.MasterTable[i], style, writer); } // Shall this column span over all the rows? if (i != 0 && column.UseAllRows && grid.RecordsPerRow == 1) continue; // Automatically set columnSpan if 'NewRowInGrid' property is enabled. if (ii < sortedColumnID.Length - 1 && columns[sortedColumnID[ii + 1]].NewRowInGrid) rowcell.InternalCellSpan = sortedColumnID.Length - ii; column.m_TreeLevel = level; if (columns[sortedColumnID[ii]].UseAllRows) column.Rowspan = grid.RecordsPerRow == 1 ? grid.MasterTable.Rows.Count : 1; column.Render(writer, rowcell); if (column.ColumnType == ColumnType.SystemColumn && ((WebGrid.SystemColumn)column).SystemColumnType == SystemColumn.SelectColumn) m_Checkboxlist.AppendFormat("{0}!", rowcell.Row.PrimaryKeyValues); if (sortedColumnID.Length - 1 == ii || (sortedColumnID.Length + 1 < ii && columns[sortedColumnID[ii + 1]].NewRowInGrid)) { EndRow(grid.MasterTable[i], writer); } } } if (tree) CreateRows(grid, true, currentRow.PrimaryKeyValues, level + 1, writer, sortedColumnID, numberOfRowsDrawn); if (grid.RecordsPerRow <= 1) continue; writer.Write("</table></td>"); if ((i + 1) == grid.MasterTable.Rows.Count && (grid.MasterTable.Rows.Count < grid.RecordsPerRow || rows < grid.RecordsPerRow)) { while (rows < grid.RecordsPerRow) { writer.Write("<td height=\"100%\" width=\"{0}%\"></td>", (100/grid.RecordsPerRow)); rows++; } } if (rows == grid.RecordsPerRow) { writer.Write("</tr>"); rows = 0; isNewRecordsPerRow = true; } rows++; } if (grid.RecordsPerRow <= 1 || grid.MasterTable.Rows.Count <= 0) return; if (rows > 1) writer.Write("</tr>"); writer.Write("</table></td></tr>"); }
internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell) { if (AllowEdit == false) { RenderLabelView(writer, cell); return; } m_IsFormElement = false; RenderDetail(true, writer, cell); }
internal void Render() { WebGridHtmlWriter writer = new WebGridHtmlWriter(m_Grid); Render(writer); }
internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell) { RenderLabelView(writer, cell); }
// 2005.01.09 - jorn - String.Compare, string.Length // 2005.01.05 - Jorn - Added check to see if there actually is a checkbox on "previous page". // Need to add a hidden field since checkbox "returns null" both for unchecked and non-existing internal void RenderDetail(bool enabled, WebGridHtmlWriter writer, RowCell cell) { if (AllowEdit == false || (Grid.DisplayView == DisplayView.Grid && AllowEditInGrid == false)) enabled = false; string uniqueId = cell.CellClientId; string strValue = DisplayText(cell); const string checkedValue = TrueValue; const string uncheckedValue = FalseValue; StringBuilder sb; if (String.Compare(strValue, checkedValue, true) == 0 && CheckedAlias != null && enabled == false) sb = new StringBuilder(CheckedAlias); else if (String.Compare(strValue, uncheckedValue, true) == 0 && UncheckedAlias != null && enabled == false) sb = new StringBuilder(UncheckedAlias); else { string bitchecked = string.Empty; string bitEnabled = string.Empty; if (String.Compare(strValue, checkedValue, true) == 0) bitchecked = " checked=\"checked\""; if (enabled == false) bitEnabled = " disabled=\"disabled\""; StringBuilder javascript = new StringBuilder(string.Empty); StringBuilder onblur = new StringBuilder(" onblur=\""); if (Grid.InputHighLight != Color.Empty) { javascript.AppendFormat( " onfocus=\"this.accessKey = this.style.backgroundColor;this.style.backgroundColor='{0}';\"", Grid.ColorToHtml(Grid.InputHighLight)); onblur.Append("this.style.backgroundColor=this.accessKey;"); } if (Grid.ColumnChangedColour != Color.Empty) { onblur.AppendFormat("isChanged(this,'{0}');", Grid.ColorToHtml(Grid.ColumnChangedColour)); } onblur.Append("\""); if (AutoPostback || string.IsNullOrEmpty(ConfirmMessage) == false) { StringBuilder eventScript = new StringBuilder(" onclick=\""); if (string.IsNullOrEmpty(ConfirmMessage) == false) eventScript.AppendFormat(" if(wgconfirm('{0}',this,'{1}')) ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'")); string link = Grid.EnableCallBack && !ForcePostBack ? Asynchronous.GetCallbackEventReference(Grid, string.Format("ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues), false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid, string.Format( "ElementPostBack!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues)); eventScript.AppendFormat("{0}\"", link); javascript.Append(eventScript); } javascript.Append(onblur); sb = new StringBuilder( string.Format( "<input {0} type=\"checkbox\" {1} {2} {4} id=\"cb_{3}\" name=\"{3}\" value=\"1\"/>", javascript, bitchecked, bitEnabled, uniqueId, Attributes)); if (string.IsNullOrEmpty(m_Displaylabel) == false) sb.AppendFormat( "<label class=\"wglabel\" id=\"label_{0}\" for=\"cb_{0}\">{1}</label>", uniqueId, m_Displaylabel); if (enabled) writer.Write("<input type=\"hidden\" id=\"{0}_cb\" name=\"{0}_cb\" value=\"{1}\" />", uniqueId, checkedValue); } if (string.IsNullOrEmpty(ToolTipInput) == false) sb = new StringBuilder(Tooltip.Add(sb.ToString(), ToolTipInput)); EditHtml(sb.ToString(), writer, cell); }
internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell) { m_IsFormElement = false; RenderDetail(false, writer, cell); }
internal void Render(WebGridHtmlWriter mywriter) { // MasterWebGrid is using SlaveGridMenu. if (((m_Grid.SystemMessage.CriticalCount == 0 && m_Grid.MasterGrid != null && m_Grid.MasterWebGrid != null && m_Grid.m_IsGridInsideGrid == false && m_Grid.MasterWebGrid.DisplaySlaveGridMenu && (m_Grid.MasterWebGrid.ActiveMenuSlaveGrid == null || m_Grid.MasterWebGrid.ActiveMenuSlaveGrid.ClientID != m_Grid.ClientID)) ) || (m_Grid.m_IsGridInsideGrid && m_Grid.MasterWebGrid != null && m_Grid.MasterWebGrid.m_HasRendered == false)) { return; } if (m_Grid.HideIfEmptyGrid && m_Grid.MasterTable.Rows.Count == 0 && m_Grid.SystemMessage.CriticalCount == 0 && !m_Grid.m_ActiveColumnFilter) { if (m_Grid.EmptyDataTemplate != null) { mywriter.Write(m_Grid.EmptyDataTemplate); } return; } m_Grid.m_HasRendered = true; if (m_Grid.Tag["wgcsslink"] != null) { mywriter.Write(m_Grid.Tag.Get("wgcsslink")); } if (m_Grid.Tag["wgscriptstyles"] != null) { mywriter.Write(m_Grid.Tag.Get("wgscriptstyles")); } if (m_Grid.PreGridTemplate != null) { mywriter.Write(m_Grid.PreGridTemplate); } string width = string.Empty; if (m_Grid.Width.IsEmpty == false) { width = string.Format(" width=\"{0}\"", m_Grid.Width); } StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); System.Web.UI.HtmlTextWriter renderBeginTag = new System.Web.UI.HtmlTextWriter(sw); m_Grid.RenderBeginTag(renderBeginTag); string webAttributes = sb.ToString(); // Remove first tag which is always 'id=' webAttributes = webAttributes.Remove(0, webAttributes.IndexOf("id=")); // Clean up.. webAttributes = webAttributes.Remove(0, webAttributes.IndexOf(" ")); webAttributes = string.Format("<table{0}", webAttributes.Remove(webAttributes.Length - 1)); #region slavegrid menu bool systemMessagetriggered = false; if (m_Grid.DisplayView == DisplayView.Detail && m_Grid.DisplaySlaveGridMenu && m_Grid.SlaveGrid.Count > 0 && m_Grid.InternalId != null) { mywriter.Write("<!--WebGrid menu starts rendering -->\n"); mywriter.Write("{0} class=\"wgmenu\" {1} cellpadding=\"0\" cellspacing=\"0\" id=\"wgMenu_{2}\"><tr><td>", webAttributes, width, m_Grid.ClientID); if (m_Grid.SystemMessage.Count > 0) { mywriter.Write(m_Grid.SystemMessage.RenderSystemMessage); if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableBookmark) { Grid.AddClientScript(mywriter, string.Format("bookmarkscroll.init();bookmarkscroll.scrollTo('wgSystemMessage_{0}')", m_Grid.ID)); } mywriter.Write("</td></tr><tr><td>"); systemMessagetriggered = true; } /* cellpadding and cellspacing are fixed because CSS does not support similar behavior*/ mywriter.Write("<table class=\"wgmenunavigation\" cellpadding=\"0\" cellspacing=\"0\"><tr align=\"left\">"); bool createmenuspace = false; foreach (Grid slavegrid in m_Grid.SlaveGrid) { if (createmenuspace) { mywriter.Write("<td class=\"wgmenuspacing\"></td>"); } else { createmenuspace = true; } if (m_Grid.ActiveMenuSlaveGrid != slavegrid) { string colorstyle = null; if (Grid.MenuInactiveColor != Color.Empty) { colorstyle = string.Format("style=\"background-color:{0}\"", Grid.ColorToHtml(Grid.MenuInactiveColor)); } if (m_Grid.IsUsingJQueryUICSSFramework) { mywriter.Write( "<td id=\"wgmenu_{0}_{1}\">{2}</td>", m_Grid.ClientID, slavegrid.ClientID, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); } else { mywriter.Write( "<td id=\"wgmenu_{0}_{1}\"><div class=\"wglefttab_off\"></div><div {2} class=\"wginactivemenu wgrighttab_off\">{3}</div></td>", m_Grid.ClientID, slavegrid.ClientID, colorstyle, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); } } else { string colorstyle = null; if (Grid.MenuActiveColor != Color.Empty) { colorstyle = string.Format("style=\"background-color:{0}\"", Grid.ColorToHtml(Grid.MenuActiveColor)); } if (m_Grid.IsUsingJQueryUICSSFramework) { mywriter.Write( "<td id=\"wgmenu_{0}_{1}\">{2}</td>", m_Grid.ClientID, slavegrid.ClientID, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); } else { mywriter.Write( "<td id=\"wgmenu_{0}_{1}\"><div class=\"wglefttab_on\"></div><div {2} class=\"wgactivemenu wgrighttab_on\">{3}</div></td>", m_Grid.ClientID, slavegrid.ClientID, colorstyle, m_Grid.SlaveGrid.GetSlaveGridAnchor(slavegrid)); } } } mywriter.Write("</tr></table></td></tr></table><br/>"); mywriter.Write("<!--WebGrid menu finished rendering -->\n"); } #endregion if (m_Grid.SystemMessage.Count > 0 && systemMessagetriggered == false) { mywriter.Write(m_Grid.SystemMessage.RenderSystemMessage); if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableBookmark) { Grid.AddClientScript(mywriter, string.Format("bookmarkscroll.init();bookmarkscroll.scrollTo('wgSystemMessage_{0}')", m_Grid.ID)); } } mywriter.Write("<!--WebGrid grid starts rendering -->\n"); mywriter.Write("{0} {1} cellpadding=\"0\" class=\"wgmaingrid\" cellspacing=\"0\" id=\"wgContent_{2}\"><tr><td>", webAttributes, width, m_Grid.ID); ApplyAjaxLoader(mywriter); if (m_Grid.SystemMessage.CriticalCount == 0) { switch (m_Grid.DisplayView) { case DisplayView.Grid: if (m_Grid.AllowEditInGrid && m_Grid.PageIndex == 0 && m_Grid.Page != null) { if (m_Grid.EnableCallBack) { mywriter.Write( "<input type=\"hidden\" id=\"{0}_where\" name=\"{0}_where\" value=\"{1}\" />", m_Grid.ClientID, HttpUtility.UrlEncode(m_Grid.FilterExpression, Encoding.Default)); } else { m_Grid.Page.ClientScript.RegisterHiddenField( string.Format("{0}_where", m_Grid.ClientID), HttpUtility.UrlEncode(m_Grid.FilterExpression, Encoding.Default)); } } RenderGrid(ref m_Grid, ref mywriter); break; case DisplayView.Detail: RenderDetail(ref m_Grid, ref mywriter); break; } } mywriter.Write("</td></tr></table>"); mywriter.Write("<!--WebGrid grid finished rendering -->\n"); if (m_Grid.Page != null && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableWebGridClientObject)) { m_Grid.JsOnData.AppendLine(); m_Grid.JsOnData.Append(WebGridClientObject.GetGridObject(m_Grid)); } if (m_Grid.Scripts == null || !m_Grid.Scripts.DisableContextMenu) { m_Grid.GetContextMenuHtml(mywriter); Grid.AddClientScript(mywriter, string.Format(contextscript, m_Grid.ID)); } if (m_Grid.ClientNotifications != null && m_Grid.ClientNotifications.Count > 0 && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableClientNotification)) { ClientNotification clientSettings = m_Grid.ClientNotification ?? Grid.DefaultClientNotification; if (clientSettings.HeaderText == null) { clientSettings.HeaderText = m_Grid.Title; } if (clientSettings.HeaderText == null) { clientSettings.HeaderText = string.Empty; } StringBuilder template = string.IsNullOrEmpty(clientSettings.Container) ? new StringBuilder( "$(document).ready( function() {{ $.jGrowl(\"{0}\", {{ header: '") : new StringBuilder( string.Format( "$(document).ready( function() {{ $('#{0}').jGrowl(\"{0}\", {{ header: '", clientSettings.Container)); template.Append(clientSettings.HeaderText.Replace("\"", "\\")); template.AppendFormat("', sticky: {0}", clientSettings.Sticky.ToString().ToLower()); template.AppendFormat(", life: {0}", clientSettings.LifeSpan); if (clientSettings.CloserTemplate != null) { template.AppendFormat(", closerTemplate: '{0}'", clientSettings.CloserTemplate.Replace("\"", "\\")); } template.Append(", closer: " + clientSettings.Closer.ToString().ToLower()); if (!string.IsNullOrEmpty(clientSettings.CssClass)) { template.AppendFormat(", theme: '{0}'", clientSettings.CssClass); } template.Append("}}); }});"); if (m_Grid.ClientNotifications.Count > 0) { foreach (string arg in m_Grid.ClientNotifications) { Grid.AddClientScript(mywriter, string.Format(template.ToString(), arg.Replace("\"", "\\"))); } } } if ((m_Grid.Scripts == null || !m_Grid.Scripts.DisableInputMask) && m_Grid.MaskedColumns.Count > 0) { StringBuilder masks = new StringBuilder(); foreach (KeyValuePair <string, string> dictionary in m_Grid.MaskedColumns) { if (masks.Length > 3) { masks.Append(", "); } masks.AppendFormat("{0}:{{ mask: {1} }}", dictionary.Key, dictionary.Value); } string options; if (m_Grid.MaskedInput != null) { options = string.Format("{{selectCharsOnFocus: {0},textAlign: {1},autoTab:{2}, attr: '{3}'}}", MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableSelectCharsOnFocus), MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableTextAlign), MaskedInput.GetStringValue(m_Grid.MaskedInput.EnableAutoTab), m_Grid.MaskedInput.Attribute); } else { options = "{selectCharsOnFocus: true,textAlign: false,autoTab:false, attr: 'alt'}"; } Grid.AddClientScript(mywriter, string.Format(meiomask, m_Grid.ID, masks, options)); } if (Anthem.Manager.IsCallBack && (m_Grid.Scripts == null || !m_Grid.Scripts.DisableHoverButtons)) { Grid.AddClientScript(mywriter, Grid.HoverButtonScript); } if (m_Grid.JsOnData.Length > 2) { mywriter.Write(@"<script type=""text/javascript"">{0}</script>", m_Grid.JsOnData.ToString()); } mywriter.Close(); if (m_Grid.Trace.IsTracing) { m_Grid.Trace.Trace("Finish Render();"); } }
internal static void CreateFilterByColumns(Grid grid, WebGridHtmlWriter writer, int[] sortedColumnID) { grid.m_RowsAdded++; writer.Write( grid.IsUsingJQueryUICSSFramework ? "<tr class=\"ui-widget wgrow\" id=\"{0}r{1}\">" : "<tr class=\"wgrow\" id=\"{0}r{1}\">", grid.ID, grid.m_RowsAdded); for (int ii = 0; ii < sortedColumnID.Length; ii++) { Column column = grid.MasterTable.Columns[sortedColumnID[ii]]; if (column.FilterByColumnCollection.Count == 0) { string columnstyle = string.Empty; string columnId = string.Format(" id=\"{0}{1}r{2}\"", grid.ID, column.ColumnId, grid.m_RowsAdded); if (grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle != Unit.Empty) columnstyle = string.Format("style=\"width: {0};\"", grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle); writer.Write("<th {0} {1}> </th>", columnstyle,columnId); continue; } ColumnHeader addcolumn = new ColumnHeader { m_Class = string.Format("{0} wggridcell", column.CssClassTitle), m_Align = column.GridAlign, m_VAlign = VerticalPosition.bottom, m_ColumnWidth = grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle, m_GridRowCount = grid.m_RowsAdded, m_GridId = grid.ID }; addcolumn.RenderBeginTag(writer,column,null,"<th"); string selectedValue = null; if (Grid.GotHttpContext && HttpContext.Current.Request.Form[string.Format("ddl{0}", column.ClientHeaderId)] != null) { selectedValue = HttpUtility.HtmlEncode( HttpContext.Current.Request.Form[string.Format("ddl{0}", column.ClientHeaderId)]); grid.State(string.Format("ddl{0}", column.ClientHeaderId), selectedValue); } else if (grid.GetState(string.Format("ddl{0}", column.ClientHeaderId)) != null) selectedValue = grid.GetState(string.Format("ddl{0}", column.ClientHeaderId)) as string; bool isdate = false; if (grid.MasterTable.Columns[column.ColumnId].ColumnType == ColumnType.DateTime) isdate = true; string eventScript = string.Empty; if (grid.Page != null) { string link = grid.EnableCallBack && !column.ForcePostBack ? Asynchronous.GetCallbackEventReference(grid, string.Format("ElementPostBack!ddl{0}", column.ColumnId), false, string.Empty, string.Empty) : grid.Page.ClientScript.GetPostBackEventReference(grid, string.Format("ElementPostBack!ddl{0}", column.ColumnId)); eventScript = string.Format(" onchange=\"{0}\" ", link); } string style = grid.MasterTable.Columns[column.ColumnId].WidthColumnHeaderTitle != Unit.Empty ? "class=\"wgeditfield wgselectbox \"" : " class=\"wgeditfield wgselectbox \" "; if (!isdate) { StringBuilder dropdownbox = new StringBuilder("<select "); dropdownbox.AppendFormat("{0} name=\"ddl{1}\" id=\"ddl{1}\" {2}><option value=\"\" selected=\"selected\">{3}</option>", style, column.ClientHeaderId, eventScript, column.Grid.GetSystemMessage("EmptySearchFilter")); if (grid.Scripts == null || !grid.Scripts.DisableSelectMenu) Grid.AddClientScript(writer, string.Format("$(document).ready(function() {{$('#ddl{0}').selectmenu({{maxHeight: {2},style:'dropdown',width: {1}}});}});", column.ClientHeaderId, column.WidthColumnHeaderTitle.Value, 400)); int i = 0; while (i < column.FilterByColumnCollection.Count) { string _value = HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]); string _title = HttpUtility.HtmlEncode(column.FilterByColumnCollection.GetKey(i)); if (selectedValue != null && selectedValue == _value) dropdownbox.AppendFormat("<option selected=\"selected\" value=\"{0}\">{1}</option>", HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]), _title); else dropdownbox.AppendFormat("<option value=\"{0}\">{1}</option>", HttpUtility.HtmlEncode(column.FilterByColumnCollection[i]), _title); i++; } writer.Write(dropdownbox); writer.Write("</select> "); } else { if (grid.DatabaseConnectionType != DataBaseConnectionType.SqlConnection) throw new GridException( string.Format("'FilterByColumn' property for 'DateTime' ({0}) columns are only supported by 'SqlConnection' connection strings.", column.ColumnId)); writer.Write("<span style=\"white-space: nowrap;vertical-align:middle;\">"); string filter = ((WebGrid.DateTime)grid.MasterTable.Columns[column.ColumnId]).SearchFilter; if (string.IsNullOrEmpty(filter)) { StringBuilder s = new StringBuilder(string.Empty); s.AppendFormat( "<a class=\"wglinkfield\" href=\"?DateFilter={0}\">{1}</a>", grid.MasterTable.Columns[column.ColumnId].ColumnId, column.Grid.GetSystemMessage("DateTimeSearch")); writer.Write(s); } else { StringBuilder s = new StringBuilder(string.Empty); s.AppendFormat( "<a class=\"wglinkfield\" href=\"#\" onclick=\"javascript:WGdisableDateTimeSearch('{0}');\";return false;\">{1}</a>", column.ColumnId,column.Grid.GetSystemMessage("DateTimeSearchReset")); writer.Write(s); } // From date writer.Write("</span>"); } addcolumn.RenderEndTag(writer,"</th>"); } writer.Write("</tr>"); }
internal override void RenderEditView(HtmlTextWriter writer, RowCell cell) { RenderLabelView(writer, cell); }
internal override void RenderLabelView(WebGridHtmlWriter writer, RowCell cell) { if (cell.Value != null && Visibility != Visibility.None) writer.Write(RenderTemplate(cell)); }
internal override void RenderLabelView(WebGridHtmlWriter writer,RowCell cell) { string image = FileSource(true,cell); if (!string.IsNullOrEmpty(PopupImageColumn)) { if (!cell.Row.Columns.Contains(PopupImageColumn)) throw new ApplicationException( string.Format(@"""PopupImageColumn"" property value for column '{0}' is not valid.", Title)); string rel = ""; if (m_PopupImageDisplayType == ImageDisplayType.Navigation || m_PopupImageDisplayType == ImageDisplayType.NavigationSlideShow) rel = string.Format("rel=\"{0}_{1}\"", Grid.ClientID, ColumnId); image = string.Format(@"<a href=""{1}"" title=""{3}"" {4} class=""wgimage_{5}""><img class=""wgimage"" src=""{0}"" alt=""{2}""/></a>", image, ((Image)cell.Row.Columns[PopupImageColumn]).GetUrl(cell.Row[PopupImageColumn]), Title, PopupImageCaption, rel, ColumnId); switch (PopupImageDisplayType) { case ImageDisplayType.Navigation: Grid.AddClientScript(writer, string.Format("$(\"a[rel='{0}_{1}']\").colorbox({{slideshow:false}});", Grid.ClientID, ColumnId)); break; case ImageDisplayType.NavigationSlideShow: Grid.AddClientScript(writer, string.Format("$(\"a[rel='{0}_{1}']\").colorbox({{slideshow:true}});", Grid.ClientID, ColumnId)); break; case ImageDisplayType.Single: Grid.AddClientScript(writer, string.Format("$(document).ready(function() {{$(\".wgimage_{0}\").colorbox();}});", ColumnId)); break; } } else image = string.Format(@"<img class=""wgimage"" src=""{0}"" alt=""{1}""/>", image, Title); if (HyperLinkColumn && Grid.DisplayView == DisplayView.Grid) { string a = Grid.EnableCallBack ? Asynchronous.GetCallbackEventReference(Grid, string.Format("RecordClick!{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues), false, string.Empty, string.Empty) : Grid.Page.ClientScript.GetPostBackEventReference(Grid, string.Format("RecordClick!{0}!{1}", ColumnId, cell.Row. PrimaryKeyValues)); string b = (String.IsNullOrEmpty(ConfirmMessage)) ? string.Empty : String.Format("if(wgconfirm('{0}',this,'{1}')) ", ConfirmMessage.Replace("'", "\\'"), Grid.DialogTitle.Replace("'", "\\'")); image = string.Format( "<a class=\"wglinkfield\" href=\"#\" onclick=\"{0}{1}\">{2}</a>", b, a, image); } LabelHtml(image, writer,cell); }
internal override void RenderLabelView(HtmlTextWriter writer, RowCell cell) { if (!Grid.EnableCallBack) throw new GridException("WebGrid must have callback enabled to use tooltip columns, you can enable this by setting 'Grid.EnableCallBack=true'"); string clientId = ToolTipClientId ?? string.Format("{0}{1}TP{2}", Grid.ID, ColumnId, cell.Row.RowIndex); string closebutton = null; if (CloseButtonText != null) closebutton = string.Format(",button: '{0}'", CloseButtonText); Grid.AddClientScript(writer, string.Format(template, clientId, Grid.ClientID, ShowMethod, HideMethod, ToolTipWidth, ToolTipHeight, string.Format("{0}!{1}", ColumnId, cell.Row.PrimaryKeyValues) , ToolTipStyle, SingleToolTip.ToString().ToLower(), ContentText, Title, closebutton)); LabelHtml(string.Format("<div class=\"wgtoolelement\" id=\"{0}{1}TP{2}\">{3}</div>", Grid.ID, ColumnId, cell.Row.RowIndex, Text), writer, cell); }
/* public static void Render(string content, string cssclass, HtmlTextWriter writer) { ColumnCell td = new ColumnCell {m_Class = cssclass}; td.RenderBeginTag(writer); writer.Write(content); td.RenderEndTag(writer); } */ public void RenderBeginTag(WebGridHtmlWriter writer,Column column,RowCell cell, string tagtype) { StringBuilder tdStart = new StringBuilder(tagtype); string name = ""; if (column != null) name = column.ColumnId; if (m_Align != HorizontalPosition.Undefined) tdStart.AppendFormat(" align=\"{0}\"", m_Align.ToString().ToLowerInvariant()); if (m_VAlign != VerticalPosition.undefined) tdStart.AppendFormat(" valign=\"{0}\"", m_VAlign.ToString().ToLowerInvariant()); if( string.IsNullOrEmpty(m_Class) == false ) tdStart.AppendFormat(" class=\"{0}\" ", m_Class); if (m_GridRowCount == -1) { if (m_ColumnWidth != Unit.Empty) tdStart.AppendFormat(" style=\"width: {0}\"", m_ColumnWidth); if (string.IsNullOrEmpty(name) == false) tdStart.AppendFormat(" id=\"{0}{1}r0\"", m_GridId, name); } else if (string.IsNullOrEmpty(name) == false && m_GridRowCount > 0) tdStart.AppendFormat(" id=\"{0}{1}r{2}\"", m_GridId, name, m_GridRowCount); else if (string.IsNullOrEmpty(name) == false) tdStart.AppendFormat(" id=\"{0}{1}\"", name, m_GridRowCount); if (m_ColumnSpan > 1) tdStart.AppendFormat(" colspan=\"{0}\"", m_ColumnSpan); // if (m_RowSpan > 1) tdStart.AppendFormat(" rowspan=\"{0}\"", m_RowSpan); if(column != null && !string.IsNullOrEmpty( writer.Grid.OnClientCellClick )) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) ea.Value = cell.Value; ea.ClientEventType = ClientEventType.OnClientColumnClick; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}", m_GridId, name, m_GridRowCount).Replace("-","A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@" onclick=""{0}(this,{1});return false"" ", writer.Grid.OnClientCellClick, jsonId); } if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellDblClick)) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) ea.Value = cell.Value; ea.ClientEventType = ClientEventType.OnClientColumnDblClick; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}", m_GridId, name, m_GridRowCount).Replace("-", "A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@" ondblclick=""{0}(this,{1});return false"" ", writer.Grid.OnClientCellDblClick, jsonId); } if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOver)) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) ea.Value = cell.Value; ea.ClientEventType = ClientEventType.OnClientColumnMouseOver; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}mouseover", m_GridId, name, m_GridRowCount).Replace("-", "A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@"onmouseover=""{0}(this,{1});return false""", writer.Grid.OnClientCellMouseOver, jsonId); } if (column != null && !string.IsNullOrEmpty(writer.Grid.OnClientCellMouseOut)) { ClientCellEventArgs ea = new ClientCellEventArgs(); ea.ColumnId = column.ColumnId; ea.RowIndex = m_GridRowCount; if (cell != null) ea.Value = cell.Value; ea.ClientEventType = ClientEventType.OnClientColumnMouseOut; string content = JavaScriptConvert.SerializeObject(ea); writer.Grid.JsOnData.AppendLine(); string jsonId = string.Format("{0}r{2}{1}mouseout", m_GridId, name, m_GridRowCount).Replace("-", "A"); writer.Grid.JsOnData.AppendFormat("{0} = {1}", jsonId, content); tdStart.AppendFormat(@"onmouseout=""{0}(this,{1});return false""", writer.Grid.OnClientCellMouseOut, jsonId); } tdStart.Append(">"); writer.Write(tdStart); }
internal override void RenderEditView(WebGridHtmlWriter writer, RowCell cell) { StringBuilder sb = new StringBuilder(); GetColumnPostBackData(cell); EnsureItems(cell); if (Items.Count > 0) { string strHeight = "5"; if (HeightEditableColumn != Unit.Empty) strHeight = HeightEditableColumn.Value.ToString(); if (ManyToManyType == ManyToManyType.Multiselect) sb.AppendFormat( "<select size={0} multiple=\"multiple\" class=\"wgeditfield\" id=\"{1}\" name=\"{1}\">", strHeight, cell.CellClientId); else { sb.Append("<table class=\"wgmanytomany\"><tr><td>"); m_Rowcounter = RecordsPerRow; } RenderDetailTree(sb, null, 0, cell); sb.Append(ManyToManyType == ManyToManyType.Multiselect ? "</select>" : "</tr></table>"); } string displayText = sb.ToString(); if (string.IsNullOrEmpty(ToolTipInput) == false) displayText = Tooltip.Add(displayText, ToolTipInput); EditHtml(displayText, writer, cell); }