private void SetAttrsAndContent( Dictionary <string, Dictionary <string, string> > attrDict, Dictionary <string, string> contentDict, TagBuilder tag, string tag_name, bool disable_override) { AttrsHelper.SetTagAttrs( attrDict, tag, tag_name); AttrsHelper.SetTagContent( contentDict, tag, tag_name, disable_override); }
private TagBuilder SetTableOutput( TagHelperOutput output, TagBuilder thead, TagBuilder tbody) { TagBuilder table = new TagBuilder("table"); table.Attributes["class"] = "table table-primary"; AttrsHelper.SetTagAttrs(AttrsTagDict, table, TagTable); table.InnerHtml.AppendHtml(thead); table.InnerHtml.AppendHtml(tbody); return(table); }
public override void Process( TagHelperContext context, TagHelperOutput output) { TagBuilder thead = new TagBuilder("thead"); SetAttrsAndContent(AttrsTagDict, ContentTagDict, thead, TagTableHead, false); TagBuilder thead_tr = new TagBuilder("tr"); SetAttrsAndContent(AttrsTagDict, ContentTagDict, thead_tr, TagTableHeadRow, false); // Active Index if (TableShowIndex) { TagBuilder th = new TagBuilder("th"); th.InnerHtml.AppendHtml(TableIndexTitle); SetAttrsAndContent(AttrsTagDict, ContentTagDict, th, TagTableHeadIndex, false); thead_tr.InnerHtml.AppendHtml(th); } foreach (var name in TableHeadDataList) { TagBuilder th = new TagBuilder("th"); th.InnerHtml.AppendHtml(name); thead_tr.InnerHtml.AppendHtml(th); } thead.InnerHtml.AppendHtml(thead_tr); TagBuilder tbody = new TagBuilder("tbody"); SetAttrsAndContent(AttrsTagDict, ContentTagDict, tbody, TagTableBody, false); if (ItemsList.Count == 0) { TagBuilder tbody_tr = new TagBuilder("tr"); SetAttrsAndContent( AttrsTagDict, ContentTagDict, tbody_tr, TagTableBodyRow, false); TagBuilder td = new TagBuilder("td"); SetAttrsAndContent( AttrsTagDict, ContentTagDict, td, TagTableBodyTd, false); td.InnerHtml.AppendHtml(NoItemsMessage); tbody_tr.InnerHtml.AppendHtml(td); tbody.InnerHtml.AppendHtml(tbody_tr); } else { if (TableColsNumbers == 0) { TableColsNumbers = ItemsList[0].Values.Count; } // Start loop table row for (int rows = 0; rows < ItemsList.Count; rows++) { var primary_key = ItemsList[rows] .FirstOrDefault(k => k.Key == TablePrimaryKey).Value; var rows_index = (rows + 1 + (ItemPerPage * (CurrentPage - 1))).ToString(); TagBuilder tbody_tr = new TagBuilder("tr"); AttrsHelper.SetTagAttrs( AttrsTagDict, tbody_tr, TagTableBodyRow); AttrsHelper.SetTagAttrs( AttrsTagDict, tbody_tr, TagTableBodyRow, rows_index); AttrsHelper.SetTagContent( ContentTagDict, tbody_tr, TagTableBodyRow, false); AttrsHelper.SetTagContent( ContentTagDict, tbody_tr, TagTableBodyRow, rows_index, false); // Show index if true if (TableShowIndex) { TagBuilder index = new TagBuilder("td"); AttrsHelper.SetTagAttrs( AttrsTagDict, index, TagTableTdIndex); AttrsHelper.SetTagAttrs( AttrsTagDict, index, TagTableTdIndex, rows_index); AttrsHelper.SetTagContent( ContentTagDict, index, TagTableTdIndex, false); AttrsHelper.SetTagContent( ContentTagDict, index, TagTableTdIndex, rows_index, false); index.InnerHtml.AppendHtml(rows_index); tbody_tr.InnerHtml.AppendHtml(index); } // Start loop table columns for (int cols = 0; cols < TableColsNumbers; cols++) { var cols_index = (cols + 1).ToString(); TagBuilder td = new TagBuilder("td"); // try to get value from try { if (TableSortDataList.Count != 0) { var tableData = ItemsList[rows].FirstOrDefault( d => d.Key.Equals(TableSortDataList[cols], StringComparison.OrdinalIgnoreCase)).Value; if (tableData != null) { td.InnerHtml.AppendHtml(tableData); } } else { var tableData = ItemsList[rows].Values.ElementAt(cols); td.InnerHtml.AppendHtml(tableData); } } catch (ArgumentOutOfRangeException) { } AttrsHelper.SetTagAttrs( AttrsTagDict, td, TagTableBodyTd); AttrsHelper.SetTagRowsOrColsAttrs( AttrsTagDict, td, TagTableBodyTdRow, primary_key, rows_index); AttrsHelper.SetTagRowsOrColsAttrs( AttrsTagDict, td, TagTableBodyTdCol, primary_key, cols_index); AttrsHelper.SetTagAttrs( AttrsTagDict, td, TagTableBodyTd, rows_index, cols_index); AttrsHelper.SetTagContent( ContentTagDict, td, TagTableBodyTd, true); AttrsHelper.SetTagRowsOrColsContent( ContentTagDict, td, TagTableBodyTdRow, primary_key, rows_index, true); AttrsHelper.SetTagRowsOrColsContent( ContentTagDict, td, TagTableBodyTdCol, primary_key, cols_index, true); AttrsHelper.SetTagContent( ContentTagDict, td, TagTableBodyTd, rows_index, cols_index, true); AttrsHelper.SetTagContent( ContentTagDict, td, TagTableBodyTdO, false); AttrsHelper.SetTagRowsOrColsContent( ContentTagDict, td, TagTableBodyTdRowO, primary_key, rows_index, false); AttrsHelper.SetTagRowsOrColsContent( ContentTagDict, td, TagTableBodyTdColO, primary_key, cols_index, false); AttrsHelper.SetTagContent( ContentTagDict, td, TagTableBodyTdO, rows_index, cols_index, false); tbody_tr.InnerHtml.AppendHtml(td); } tbody.InnerHtml.AppendHtml(tbody_tr); } } if (!DisablePanel) { if (!DisablePanelHead) { TagBuilder panel_head = new TagBuilder("div"); AttrsHelper.SetTagAttrs(AttrsTagDict, panel_head, TagTablePanelHead); AttrsHelper.SetTagContent(ContentTagDict, panel_head, TagTablePanelHead, false); AttrsHelper.SetTagContent(ContentTagDict, panel_head, TagTablePanelHeadO, true); output.Content.AppendHtml(panel_head); } if (!DisablePanelBody) { TagBuilder panel_body = new TagBuilder("div"); AttrsHelper.SetTagAttrs(AttrsTagDict, panel_body, TagTablePanelBody); AttrsHelper.SetTagContent(ContentTagDict, panel_body, TagTablePanelBody, false); AttrsHelper.SetTagContent(ContentTagDict, panel_body, TagTablePanelBodyO, true); output.Content.AppendHtml(panel_body); } output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; output.Content.AppendHtml( SetTableOutput(output, thead, tbody)); } else { output.TagName = "table"; output.TagMode = TagMode.StartTagAndEndTag; output.Content.AppendHtml( SetTableOutput(output, thead, tbody) ); } }