Exemplo n.º 1
0
        /// <summary>
        /// If multiple rows are necessary, the passed row becomes the current row becomes the first row.
        /// The new row is returned.
        /// </summary>
        /// <param name="gv"></param>
        /// <returns></returns>
        private GridViewRow FormatMultiRowHeader(GridViewEx gv)
        {
            // Start by assuming that we will need a new row
            // Set row index to -2 to indicate that this is the second header row.
            // GridViewMatrixCell looks at this to determine whether the first row or the second row of the header should
            // be rendered
            GridViewRow rowAdded = new GridViewRow(ROW_SECOND_LINE_HEADER,
                                                   -1, DataControlRowType.Header, DataControlRowState.Normal);

            for (int i = 0; i < this.Cells.Count; ++i)
            {
                DataControlFieldCell cellOrig = (DataControlFieldCell)this.Cells[i];
                if (!cellOrig.ContainingField.Visible)
                {
                    // Ignore invisible columns
                    continue;
                }
                char[]   seperator = new char[] { '|' };
                string[] tokens    = cellOrig.ContainingField.HeaderText.Split(seperator, StringSplitOptions.RemoveEmptyEntries);
                //string[] expressions = gv.SortExpression.Split(';');
                //List<string> listSortExpressions = new List<string>(expressions);
                switch (tokens.Length)
                {
                case 0:
                    // Empty header
                    cellOrig.RowSpan = 2;
                    break;

                case 1:
                    // single line header
                    cellOrig.RowSpan       = 2;
                    cellOrig.VerticalAlign = VerticalAlign.Middle;
                    cellOrig.Text          = tokens[0];
                    break;

                case 2:
                    // Tow header rows are in fact needed
                    cellOrig.Text = tokens[0];
                    DataControlFieldCell cellNew;
                    if (cellOrig.ContainingField is IHasCustomCells)
                    {
                        IHasCustomCells cancreate = cellOrig.ContainingField as IHasCustomCells;
                        cellNew = cancreate.CreateCell(DataControlCellType.Header);
                    }
                    else
                    {
                        cellNew = new GridViewExHeaderCell(gv, cellOrig.ContainingField);
                    }
                    cellNew.Text = tokens[1];
                    rowAdded.Cells.Add(cellNew);
                    break;

                default:
                    throw new NotSupportedException("At most one pipe character is allowed in the header text");
                }
            }

            if (rowAdded.Cells.Count == 0)
            {
                // Revert all the rowspans back to default
                foreach (TableCell cell in this.Cells)
                {
                    cell.RowSpan = 0;
                }
                rowAdded = null;
            }
            else
            {
                SetColumnSpan();
            }
            return(rowAdded);
        }
Exemplo n.º 2
0
        /// <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}&nbsp;", _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
        }