Ejemplo n.º 1
0
        /// <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
        }
Ejemplo 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
        }
Ejemplo n.º 3
0
        /// <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("&nbsp;&nbsp;");
                    // 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("&nbsp;&nbsp;");
                    //++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("&nbsp;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
        }
Ejemplo n.º 4
0
        protected override void RenderContents(HtmlTextWriter writer)
        {
//#if DEBUG
//            if (!_gv.PreSorted && string.IsNullOrEmpty(_gv.SortExpression))
//            {
//                throw new InvalidOperationException("You are attempting to display the " + _gv.ID + " list in an unsorted order");
//            }
//#endif
            if (this.HasControls())
            {
                // Must be HeaderTemplate of Template field. No sort icons to be displayed here
                base.RenderContents(writer);
                return;
            }
            SortExpression colSortExpression;
            int            nSortIndex;
            bool           bIsSortable = _gv.AllowSorting;

            if (string.IsNullOrEmpty(this.ContainingField.SortExpression))
            {
                bIsSortable       = false;
                nSortIndex        = -1;
                colSortExpression = null;
            }
            else
            {
                colSortExpression = new SortExpression(this.ContainingField.SortExpression);
                if (_gv.SortExpressions.Any())
                {
                    nSortIndex = _gv.SortExpressions.Select((p, i) => p.Equals(colSortExpression) ? i : -1).Max();
                }
                else
                {
                    nSortIndex = -1;
                }
            }


            if (this.ColumnSpan == 0)
            {
                // Case 1: Sortable with icon
                // Case 2: Sortable without icon
                // Case 3: Not sortable with icon
                // Case 4: Not sortable, no icon
                if (bIsSortable)
                {
                    // Sortable
                    SortExpressionCollection coll = new SortExpressionCollection(_gv.SortExpressions, colSortExpression);

                    //string script = string.Format("javascript:gridviewex_submit('{0}', '{1}', 'Sort${2}');",
                    //    this.Page.Form.ClientID, _gv.UniqueID, coll);
                    string script = string.Format("{0}", coll);

                    if (nSortIndex < 0)
                    {
                        // Case 2
                        RenderSortableNoIcon(writer, script);
                    }
                    else
                    {
                        colSortExpression = _gv.SortExpressions[nSortIndex];
                        RenderSortableWithIcon(writer, script, colSortExpression.GetSortDirection(), nSortIndex + 1);
                    }
                }
                else
                {
                    // Not sortable
                    if (nSortIndex < 0)
                    {
                        // Case 4
                        writer.Write(this.Text);
                    }
                    else
                    {
                        // Case 3
                        colSortExpression = _gv.SortExpressions[nSortIndex];
                        RenderNotSortableWithIcon(writer, this.Text, colSortExpression.GetSortDirection(), nSortIndex + 1);
                    }
                }
            }
            else
            {
                // Top row of the header should never have icons
                // Case 4
                writer.Write(this.Text);
            }
        }