Beispiel #1
0
        /// <summary>
        ///     渲染List到writer
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="lists">表头同一层的List</param>
        /// <param name="style">表头样式</param>
        /// <param name="maxDepth">最大深度</param>
        /// <param name="currentDepth">当前深度</param>
        private void RenderListToWriter(ref string writer, PFGrid grid, IList <PFGridMultiHeader> lists, int maxDepth, int currentDepth = 1)
        {
            //因为header内部是td,可以认为首尾已经各有一个tr
            if (lists != null)
            {
                //显示下一层
                var next = new List <PFGridMultiHeader>();
                //显示头
                foreach (var i in lists)
                {
                    i.RenderHeaderToWrite(ref writer, grid, maxDepth, currentDepth);

                    if (i.Children != null)
                    {
                        next.AddRange(i.Children);                    //为了免于遍历两次,放到这里--wxj20180713
                    }
                }
                ////显示下一层
                //var next = new List<PFGridMultiHeader>();
                //foreach (var i in lists)
                //{
                //    if (i.Children != null) next.AddRange(i.Children);
                //}
                if (next.Count > 0)
                {
                    writer += "</tr>";
                    writer += string.Format("<tr class='{0}'>", grid.GetHeadClass());
                    RenderListToWriter(ref writer, grid, next, maxDepth, ++currentDepth);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///     渲染到writer
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="style">表头样式</param>
        public string Html(PFGrid grid)
        {
            if (Children == null)
            {
                return("");
            }

            var selectTh        = "";
            var depth           = GetDepth() - 1;
            var selectThRowSpan = depth > 1 ? ("rowspan=" + depth) : "";

            switch (grid.GetSelectMode())
            {
            case PFGrid.SelectMode.Single:
                selectTh = string.Format("<th {0}>选择</th>", selectThRowSpan);
                break;

            case PFGrid.SelectMode.Multi:
                selectTh = string.Format("<th {0}><input type=\"checkbox\" class=\"pf-row-select-all\">选择</th>", selectThRowSpan);
                break;

            default:
                break;
            }
            var html = string.Format("<thead><tr  class='{0}' >{1}",
                                     grid.GetHeadClass(),
                                     selectTh
                                     );

            RenderListToWriter(ref html, grid, Children, depth);//第一层的header是不输出的,所以要减1
            html += "</tr></thead>";
            return(html);
        }