private void AddCellProperties(FWTableColumn column, FWTableCellElement cell) { if (column.Css != null) { cell.AddCssClass(column.Css); } //Checks to see if the property is hidden if (column.IsHidden) { cell.AddCssClass("hidden"); } foreach (var attribute in column.Attributes) { cell.Attributes.Add(attribute.Key, attribute.Value); } if (column.Metadata != null) { //Sets the column size if was defined in the metadata. if (column.Metadata.AdditionalValues.ContainsKey(nameof(FWSizeAttribute))) { var sizes = column.Metadata.AdditionalValues[nameof(FWSizeAttribute)] as List <FWSizeAttribute>; foreach (var item in sizes) { cell.AddCssClass(FWGridSizeHelper.GetCss(item.Size, item.Device)); } } } }
/// <summary> /// Creates a new header cell. /// </summary> /// <param name="column">The column object.</param> /// <returns>A FWTableCellElement object.</returns> protected virtual FWTableCellElement CreateHeaderCell(FWTableColumn column) { var cell = new FWTableCellElement(true); //Adds the text to the <th> cell.Add(column.Header); AddCellProperties(column, cell); return(cell); }
/// <summary> /// Creates a new line cell. /// </summary> /// <param name="item">The cell value.</param> /// <param name="column">The column object.</param> /// <returns>A FWTableCellElement object.</returns> protected virtual FWTableCellElement CreateLineCell(object item, FWTableColumn column) { var cell = new FWTableCellElement(false); if (item != null) { var control = column.GetValue(RequestContext, item, Index); cell.Value = control.ToString(); } AddCellProperties(column, cell); return(cell); }
/// <summary> /// Creates the control main element. /// </summary> /// <returns>The IFWHtmlElement object representation of the control.</returns> protected override IFWHtmlElement CreateControl() { if (_autoGenerateColumns) { GenerateColumnsFromMetadata(); } // Reorder the columns Columns = Columns.OrderBy(f => f.Order).ToList(); var table = new FWTagBuilder("table") { DataType = "fw-table" }; table.AddCssClass("table table-responsive-sm m-table m-table--head-separator-metal"); table.Attributes.AddRange(Attributes); if (!string.IsNullOrWhiteSpace(CustomCss)) { table.AddCssClass(CustomCss); } //Creates the table header FWTagBuilder head = new FWTagBuilder("thead"); head.AddCssClass("thead-default"); var tableHead = new FWTagBuilder("tr"); if (!AutoSizeColumns) { tableHead.AddCssClass("row"); } if (_color.HasValue) { tableHead.AddCssClass(_color.Value.GetDescription()); } tableHead.Attributes.Add("role", "row"); //Iterates through the columns to add the header foreach (var column in Columns) { //Creates a new <th> element FWTableCellElement headercell = CreateHeaderCell(column); tableHead.Add(headercell); } //Adds the header to the table head.Add(tableHead); table.Add(head); TableBody = new FWTagBuilder("tbody"); //Iterates through the columns to add the values to the table if (Data != null) { LineIndex = 0; foreach (var dataitem in Data) { if (CheckEndOfTable()) { break; } var line = CreateLine(dataitem); line.Attributes.Add("data-control-child", "table"); if (!AutoSizeColumns) { line.AddCssClass("row"); } foreach (var column in Columns) { //Create a new <td> element var cell = CreateLineCell(dataitem, column); line.Add(cell); } TableBody.Add(line); LineIndex++; } } //Adds the body to the table table.Add(TableBody); return(table); }