private static void RenderGroupByMarker(HtmlTextWriter writer) { writer.AddAttribute("sortexpr", "$"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-state-active"); writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap"); writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center"); writer.AddAttribute(HtmlTextWriterAttribute.Title, "Group by Marker"); writer.RenderBeginTag(HtmlTextWriterTag.Li); //ButtonEx btn = new ButtonEx(); //btn.Icon = IconType.Custom; //btn.CustomIconName = "ui-icon-arrowthick-1-nw"; //btn.ButtonState = ButtonState.None; //btn.RenderControl(writer); ButtonEx.RenderIcon(writer, "ui-icon-arrowthick-1-nw"); writer.Write("Master Columns"); //btn.CustomIconName = "ui-icon-arrowthick-1-ne"; //btn.RenderControl(writer); ButtonEx.RenderIcon(writer, "ui-icon-arrowthick-1-ne"); writer.RenderEndTag(); //li }
/// <summary> /// This function renders sort icon on the basis of /// passed direction and visibility by the caller. /// </summary> private static void RenderSortIcon(HtmlTextWriter writer, SortExpression sortExpr, int?sequence) { SortDirection dir = sortExpr.GetSortDirection(); if (dir == SortDirection.Ascending) { //_btnIcon.CustomIconName = " ui-icon-triangle-1-n"; ButtonEx.RenderIcon(writer, "ui-icon-triangle-1-n"); } else { //_btnIcon.CustomIconName = " ui-icon-triangle-1-s"; ButtonEx.RenderIcon(writer, "ui-icon-triangle-1-s"); } //_btnIcon.RenderControl(writer); // Dynamically replaced with sort sequence writer.RenderBeginTag(HtmlTextWriterTag.Sup); writer.Write(sequence); writer.RenderEndTag(); // sup }
private static void RenderSortIcon(HtmlTextWriter writer, SortDirection dirIcon, int nSortSequence) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "gvex-sort-icon"); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.RenderBeginTag(HtmlTextWriterTag.Sup); //ButtonEx btn = new ButtonEx(); //btn.Icon = IconType.Custom; string str = string.Format("ui-icon-triangle-1-{0}", dirIcon == SortDirection.Ascending ? "n" : "s"); ButtonEx.RenderIcon(writer, str); //btn.ButtonState = ButtonState.None; //btn.RenderControl(writer); writer.RenderEndTag(); if (nSortSequence > 0) { writer.RenderBeginTag(HtmlTextWriterTag.Sup); writer.Write("{0}", nSortSequence); writer.RenderEndTag(); // sup } writer.RenderEndTag(); // span }
/// <summary> /// Finds grid view of the page in which our control was placed by using property GridViewExId /// Renders the markup for the SortColumnChooser control and then applies sorting in the contol /// based on the DefaultSortExpression of the grid. Apllies direction based on grid view property /// DefaultSortDirection. /// </summary> /// <param name="writer"></param> protected override void RenderContents(HtmlTextWriter writer) { base.RenderContents(writer); writer.AddStyleAttribute("float", "left"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-widget"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-widget-header"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.Write("Available Columns"); writer.RenderEndTag(); //div writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_1"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-widget-content"); writer.RenderBeginTag(HtmlTextWriterTag.Ul); if (this.EnableGroupBy && _gv.SortExpressions.CountMasterExpressions == 0) { // If sort columns already contain group by marker, do not add it here RenderGroupByMarker(writer); } foreach (DataControlField col in _gv.Columns.Cast <DataControlField>().Where(p => !string.IsNullOrEmpty(p.SortExpression))) { // Only those columns which are sortable, and not part of default expression SortExpression colSortExpr = new SortExpression(col.SortExpression); if (!_gv.SortExpressions.Contains(colSortExpr)) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-state-default"); //string sortExprFixed = SortFormatProvider.FixSortExpressions(col.SortExpression); writer.AddAttribute("sortexpr", colSortExpr.ToString()); IHasHeaderToolTip tip = col as IHasHeaderToolTip; if (tip != null && !string.IsNullOrEmpty(tip.HeaderToolTip)) { writer.AddAttribute(HtmlTextWriterAttribute.Title, tip.HeaderToolTip); } writer.RenderBeginTag(HtmlTextWriterTag.Li); writer.Write(col.HeaderText.Replace("|", " - ")); writer.Write(" "); // Hidden Icon RenderSortIcon(writer, colSortExpr, null); writer.RenderEndTag(); //li } } writer.RenderEndTag(); //ul writer.RenderEndTag(); //div writer.AddStyleAttribute("float", "right"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-widget"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-widget-header"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.Write("Sort Columns"); writer.RenderEndTag(); //div writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_2"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-widget-content"); writer.RenderBeginTag(HtmlTextWriterTag.Ul); //int sequence = 0; for (int i = 0; i < _gv.SortExpressions.Count; ++i) { // Only those columns which are part of default expression if (i > 0 && i == _gv.SortExpressions.CountMasterExpressions) { RenderGroupByMarker(writer); } DataControlField dcf = _gv.Columns.Cast <DataControlField>().FirstOrDefault( p => _gv.SortExpressions[i].Equals(p.SortExpression)); if (dcf != null) { IHasHeaderToolTip tip = dcf as IHasHeaderToolTip; if (tip != null && !string.IsNullOrEmpty(tip.HeaderToolTip)) { writer.AddAttribute(HtmlTextWriterAttribute.Title, tip.HeaderToolTip); } writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-state-default ui-priority-primary"); //string sortExprFixed = SortFormatProvider.FixSortExpressions(sortExpr); writer.AddAttribute("sortexpr", _gv.SortExpressions[i].ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Li); writer.Write(dcf.HeaderText.Replace("|", " - ")); writer.Write(" "); //++sequence; RenderSortIcon(writer, _gv.SortExpressions[i], i + 1); writer.RenderEndTag(); //li } } if (_gv.SortExpressions.Count == _gv.SortExpressions.CountMasterExpressions) { // The group by marker is at the very end. Render it now RenderGroupByMarker(writer); } writer.RenderEndTag(); //ul writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID); writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox"); writer.AddAttribute(HtmlTextWriterAttribute.Value, _gv.SortExpressions.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.RenderEndTag(); writer.Write(" Use these sort columns"); writer.RenderEndTag(); //p writer.RenderEndTag(); //div // Instructions writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write("Use drag and drop to add, remove or rearrange sort columns. Click on the sort icon to toggle sort direction. A mouse is required."); writer.RenderEndTag(); //p //_btnIcon.CustomIconName = "ui-icon-transferthick-e-w"; //_btnIcon.RenderControl(writer); ButtonEx.RenderIcon(writer, "ui-icon-transferthick-e-w"); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write("Removing all sort columns will revert to default sorting."); writer.RenderEndTag(); //p // div which clears floats writer.AddStyleAttribute("clear", "both"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderEndTag(); //writer.RenderEndTag(); //div }
/// <summary> /// Master row markup looks like: /// <tr> /// <td colspan="x"> /// <table> /// <tbody> /// <tr> /// <td>Header Text 1: Header Value 1</td> /// ... /// </tr> /// </tbody> /// </table> /// </td> /// </tr> /// </summary> /// <remarks> /// The method renders the content of <c>GridViewExMasterRow</c> with in gridview header using custom HTML table. /// </remarks> private void RenderMasterRowHeader(HtmlTextWriter writer) { // Render the master row before we render the normal row if (_rowInfo._masterRowIndex != 0) { // We are not the first master row. // Enclose the rows of this master in a seperate tbody for ease of scripting writer.Write("</tbody><tbody>"); } writer.AddAttribute(HtmlTextWriterAttribute.Class, "gvex-masterrow ui-widget-content"); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "right"); writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap"); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.Write("{0:N0} ", _rowInfo._masterRowIndex + 1); /* * <A class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"> * <SPAN class="ui-button-icon-primary ui-icon ui-icon-gear" /> * <SPAN class=ui-button-text>Hello</SPAN> * */ //Folder icon here writer.RenderBeginTag(HtmlTextWriterTag.Sup); ButtonEx.RenderIcon(writer, "ui-icon-folder-open"); writer.RenderEndTag(); // sup; writer.RenderEndTag(); //td // Here are aggregating the column spans of each visible header cell. If the column span is 0, we // treat it as 1. int visibleColumnCount = this.Grid.HeaderRow.Cells.Cast <DataControlFieldHeaderCell>() .Where(p => p.Visible) .Aggregate(0, (total, next) => total + (next.ColumnSpan == 0 ? 1 : next.ColumnSpan)); // Subtract 2 for the first and last columns int nColSpan = visibleColumnCount - 2; writer.AddAttribute(HtmlTextWriterAttribute.Colspan, nColSpan.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Td); int i = 0; foreach (int masterIndex in this.Grid.MasterColumnIndexes.OrderBy(p => p)) { DataControlField col = this.Grid.Columns[masterIndex]; SortExpression colSortExpression = new SortExpression(col.SortExpression); int nSortIndex = this.Grid.SortExpressions.Select((p, index) => p.Equals(colSortExpression) ? index : -1) .Single(p => p != -1); SortDirection dirIcon = colSortExpression.GetSortDirection(); col.ItemStyle.AddAttributesToRender(writer); writer.AddAttribute(HtmlTextWriterAttribute.Class, "header-entry"); TableCell cell = this.Cells[masterIndex]; if (cell.HasControls()) { // Ignore header text writer.RenderBeginTag(HtmlTextWriterTag.Div); foreach (Control ctl in cell.Controls) { ctl.RenderControl(writer); } writer.RenderEndTag(); // div } else { writer.RenderBeginTag(HtmlTextWriterTag.Span); if (string.IsNullOrEmpty(col.HeaderText)) { writer.Write(cell.Text); } else { writer.RenderBeginTag(HtmlTextWriterTag.Strong); GridViewExHeaderCell.RenderNotSortableWithIcon(writer, col.HeaderText, dirIcon, nSortIndex + 1); writer.RenderEndTag(); // strong writer.Write(": {0}", cell.Text); } writer.RenderEndTag(); // span } ++i; if (i % 2 == 0) { writer.WriteBreak(); } } writer.RenderEndTag(); //td // Row count writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "right"); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.Write("{0:N0} row{1}", _rowInfo._countRowsInMaster, _rowInfo._countRowsInMaster == 1 ? "" : "s"); writer.RenderEndTag(); writer.RenderEndTag(); //tr }