/// <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); } } }
/// <summary> /// 渲染表头td到writer /// </summary> /// <param name="writer"></param> /// <param name="maxDepth">最大深度</param> /// <param name="currentDepth">当前深度</param> private void RenderHeaderToWrite(ref string writer, PFGrid grid, int maxDepth, int currentDepth) { if (string.IsNullOrWhiteSpace(_text)) { return; } //if (Children != null && Children.Count > 1) if (Children != null && Children.Count > 0) //大于0才是对的--wxj20180906 { _columnSpan = GetAllLeafCount(a => a.Visible); //GetAllChildrenCount();// } else if (maxDepth > currentDepth) { _rowSpan = maxDepth - currentDepth + 1; } var styles = new List <string>(); if (!Visible) { styles.Add("display:none"); } if (//(!_isFirstColumn)&& (!string.IsNullOrWhiteSpace(_width))) { styles.Add("width:" + _width); styles.Add("min-width:" + _width);//th的width是不会撑开table的,但min-width可以 } ; //if (!string.IsNullOrWhiteSpace(_width)) { styles.Add("width:"+_width); }//现在的树组件,如果只有一列不设置宽度时,那列的样式就会很长,另外,树型列的宽度也不应该设置.所以暂时让TreeGrid自己控制列宽吧 var style = styles.Any() ? string.Format("style ='{0}' ", string.Join(";", styles)) : ""; var dataIndex = string.IsNullOrWhiteSpace(_dataIndex) ? "" : ("field-name=" + _dataIndex); writer += string.Format("<th {1} {2} {3} {4} >{0}</th>", _text, _columnSpan > 1 ? ("colspan=" + _columnSpan) : "", _rowSpan > 1 ? ("rowspan=" + _rowSpan) : "", style, dataIndex); }
/// <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); }