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)
 {
     tb.AddCell(html, colspan, klass, attrs, type, width);
 }
Esempio n. 2
0
        /// <summary>
        /// Build table from given 'data'
        /// </summary>
        /// <param name="data">TableData</param>
        /// <param name="hdr">Array of header strings</param>
        /// <param name="title">Table title (displayed in large font)</param>
        /// <param name="tooltip">Add tooltip to title</param>
        /// <param name="page_name">If want to add sorting to table columns, see AddHeader, also for SliderTab</param>
        /// <param name="sortby">as above</param>
        /// <param name="sortorder">as above</param>
        /// <param name="noempty">Don't show empty table</param>
        /// <param name="addBR">Add <BR> after table</param>
        /// <param name="inSlider"></param>
        /// <param name="tableID"></param>
        /// <param name="initiallyOpen"></param>
        /// <param name="widths"></param>
        /// <returns></returns>
        public static string BuildTable(TableData data,
                                        string[] hdr       = null,
                                        string title       = null,
                                        string tooltip     = null,
                                        string page_name   = null,
                                        bool sorthdr       = false,
                                        string sortby      = null,
                                        string sortorder   = "asc",
                                        bool noempty       = false,
                                        bool addBR         = true,
                                        bool?inSlider      = null,
                                        string tableID     = null,
                                        bool initiallyOpen = true,
                                        string width       = null,
                                        string[] widths    = null
                                        )
        {
            if (inSlider == null)
            {
                inSlider = InSliderDefault;
            }

            // If no title, but header array - don't use slider
            if (title == null && hdr != null)
            {
                inSlider = false;
            }

            // If 'noempty' is true - don't display empty table at all
            if ((data == null) || (data.Count == 0 && noempty))
            {
                return("");
            }

            // Work out ncols, either from hdr.Length or lenght of first row
            int ncols = (hdr != null) ? hdr.Length : data[0].Count;

            //
            object _hdr_ = (title == "notitle") ? null : (title != null) ? title : (object)hdr;

            TableBuilder table = new TableBuilder(_hdr_, ncols, tooltip,
                                                  page_name: page_name,
                                                  sorthdr: sorthdr,
                                                  sortby: sortby,
                                                  sortorder: sortorder,
                                                  inSlider: inSlider,
                                                  tableID: tableID,
                                                  width: width
                                                  );

            // If pass 'title' - then 'hdr' is displayed in second row
            if (hdr != null && title != null)
            {
                //if(title != "notitle" )
                //    table.AddBlankRow();
                table.AddRowHeader(hdr);
            }

            // Work out sort column
            // Note: 'sortby' should be from this array
            if (sortby != null)
            {
                int sort_col = Array.IndexOf(hdr, sortby);
                Debug.Assert(sort_col >= 0);
                if (sort_col >= 0)
                {
                    IComparer <List <string> > comparer = new ComparingClass(sort_col, sortorder);
                    data.Sort(comparer);
                }
            }

            // Add rows from 'data'
            foreach (var row in data)
            {
                table.AddRow();
                Debug.Assert(row.Count <= ncols);

                for (int i = 0; i < row.Count; i++)
                {
                    table.AddCell(row[i], colspan: row.Count == 1 ? ncols : 1, width: (widths != null && i < widths.Length) ? widths[i] : null);
                }

                table.EndRow();
            }

            return(table.Build(addBR, initiallyOpen));
        }