private StringBuilder RenderHtmlTable(StringBuilder thead, StringBuilder tbody) { var html = new StringBuilder($"<table{_TableAttHtml}>"); if (this._HtmlTableHelperBuilder != null) { var attrs = this._HtmlTableHelperBuilder.Caption.Attributes; var htmlAtt = attrs != null ? string.Join("", HtmlTableGeneraterFactory.AttributeToHtml(attrs).Select(s => $" {s.Key}=\"{Encode(s.Value)}\" ")) : ""; html.Append($"<caption{htmlAtt}>{_HtmlTableHelperBuilder.Caption.Content}</caption>"); } html.Append($"<thead><tr{_TrAttHtml}>{thead}</tr></thead>"); html.Append($"<tbody>{tbody.ToString()}</tbody>"); html.Append("</table>"); return(html); }
private static string ToHtmlTableByIEnumrable <T>(IEnumerable <T> enums, object tableAttributes = null, object trAttributes = null, object tdAttributes = null, HtmlTableSetting HTMLTableSetting = null) { var htmltablegenerater = HtmlTableGeneraterFactory.CreateInstance(tableAttributes, trAttributes, tdAttributes, HTMLTableSetting); // Q: Why not only IEnumerable<IDictionary> ? // A: Example Dapper Dynamic Query Only implement IDictionary<string,object> without IDictionary // Q: Why not use overload ToHtmlTable<TKey,TValue>(this IEnumerable<Dictionary<Tkey,TValue>> enums)? // A: Because ToHtmlTable<T>(this IEnumerable<T> enums) and ToHtmlTable<TKey,TValue>(this IEnumerable<Dictionary<Tkey,TValue>> enums) // System prefer use the former // ps. https://stackoverflow.com/questions/54251262/c-sharp-overload-key-value-and-non-key-value-type-using-var-without-specifying if (enums is IEnumerable <IDictionary <string, object> > ) //Special for Dapper Dynamic Query { return(htmltablegenerater.ToHtmlTableByKeyValue(enums as IEnumerable <IDictionary <string, object> >)); } else if (enums is IEnumerable <IDictionary> ) { return(htmltablegenerater.ToHtmlTableByKeyValue(enums as IEnumerable <IDictionary>)); } else { return(htmltablegenerater.ToHtmlTableByProperties(enums)); } }
public static string ToHtmlTable(this System.Data.DataTable datatable, object tableAttributes = null, object trAttributes = null, object tdAttributes = null, HtmlTableSetting HTMLTableSetting = null) { var htmltablegenerater = HtmlTableGeneraterFactory.CreateInstance(tableAttributes, trAttributes, tdAttributes, HTMLTableSetting); return(htmltablegenerater.ToHtmlTableByDataTable(datatable)); }