Esempio n. 1
0
        public void AddCell(string html,
                            int colspan  = 1,
                            string klass = "device_status_image" /*"tablecell"*/,
                            string attrs = "",
                            string type  = "td",
                            string width = null)
        {
            if (html == null)
            {
                html = "";
            }

            // If cell is just an image (i.e. check mark) - align it in center
            bool isImg = Regex.Match(html, @"^<img (.+)/>").Groups.Count > 1;

            if (isImg)
            {
                attrs += " style='text-align: center;'";
            }

            attrs += PageBuilder.fmtHTMLPair("width", width);

            html = $"<{type} {attrs} class='{klass}' colspan='{colspan}'>{html}</{type}>";
            stb.Append(html);
            ncols_row += colspan;
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="header"><Can be a string, or string array/param>
        /// <param name="ncols">If header is a string then also need ncols</param>
        /// <param name="tooltip"></param>
        /// <param name="klass"></param>
        /// <param name="border"></param>
        /// <param name="width"></param>
        /// <param name="attrs"></param>
        /// <param name="page_name">If want to add sorting to table columns, see AddHeader/BuildHeaderLink</param>
        /// <param name="sorthdr">As above</param>
        /// <param name="sortby">As above</param>
        /// <param name="sortorder">As above</param>
        /// <param name="tableID">ID for table and SliderTab</param>
        /// <param name="inSlider">Put table inside SliderTab</param>
        public TableBuilder(object header,
                            int ncols        = 0,
                            string tooltip   = null,
                            string klass     = "",
                            int border       = -1,
                            string width     = null,
                            string attrs     = "",
                            string page_name = null,
                            bool sorthdr     = false,
                            string sortby    = null,
                            string sortorder = "asc",
                            string tableID   = null,
                            bool?inSlider    = null)
        {
            if (tableID == null)
            {
                tableID = $"table{++tableCnt}";
            }
            this.tableID = tableID;

            // If not specified - get from settings
            if (inSlider == null)
            {
                inSlider = InSliderDefault;
            }

            this.inSlider = (bool)inSlider;

            // Get ncols from header if it's an array
            if (header != null)
            {
                Type hdrType = header.GetType();
                if (hdrType.IsArray && ncols <= 0)
                {
                    ncols = (header as Array).Length;
                }
            }

            this.ncols     = ncols;
            this.page_name = page_name;
            this.sorthdr   = sorthdr;
            this.sortby    = sortby;
            this.sortorder = sortorder;

            if (tooltip != null)
            {
                header += PageBuilder.MyToolTip(tooltip);
            }

            attrs += " cellpadding = '0' cellspacing = '0' ";
            // Add border if specified
            attrs += PageBuilder.fmtHTMLPair("border", border, "");
            // Add width if specified
            attrs += PageBuilder.fmtHTMLPair("width", width, "");
            // Add width if specified
            attrs += PageBuilder.fmtHTMLPair("id", tableID, "");

            if (width == null)
            {
                klass += " full_width_table_99_percent"; // full_width_table, full_width_table_100_percent
            }
            string html = $"<table {attrs} class='{klass}'>";

            stb.Append(html);

            AddTableHeader(header);
        }