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> /// Overrides the default CreateHeaderCell to add Grid behavior. /// </summary> /// <param name="column">The column object.</param> /// <returns>A FWTableCellElement object.</returns> protected override FWTableCellElement CreateHeaderCell(FWTableColumn column) { var cell = base.CreateHeaderCell(column); if (column.IsSortable) { cell.AddCssClass("sorting"); cell.Attributes.Add("data-sorting", column.SortName); if (_sortInfo.ContainsKey(column.SortName)) { cell.Attributes.Add("data-sorting-direction", _sortInfo[column.SortName].ToString()); var iconDirection = _sortInfo[column.SortName] == FWSortDirection.Descending ? "down" : "up"; var icon = cell.Add(new FWTagBuilder("i")); icon.AddCssClass($"fa fa-angle-double-{iconDirection}"); } else { // If the cell is not beeing sorted, set its direction to 'ascending' cell.Attributes.Add("data-sorting-direction", column.SortDirection.ToString()); } } if (_allowSelect && _keyPropertyName == column.Property.Name) { //Marks the key column to allow selection cell.Attributes.Add("data-key", "true"); } return(cell); }
/// <summary> /// Creates a table column. /// </summary> /// <param name="metadata">The model metadata.</param> /// <param name="property">The proeprty info.</param> /// <returns>A FWTableColumn object.</returns> protected virtual FWTableColumn CreateColumn(ModelMetadata metadata, PropertyInfo property) { var column = new FWTableColumn(metadata) { Header = FWStringLocalizer.GetModelResource(property.Name, ListType.Name) }; return(column); }
/// <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> /// Generates the columns from the model metadata. /// </summary> protected virtual void GenerateColumnsFromMetadata() { // Gets the properties IEnumerable <PropertyInfo> properties = FWReflectionHelper.GetPublicProperties(ListType); // Finds the property metadata ModelMetadata listMetadata = RequestContext.MetadataProvider.GetMetadataForType(ListType); // Creates all data columns foreach (var prop in properties) { var itemMetadata = listMetadata.Properties.Where(f => f.PropertyName == prop.Name).First(); if (!itemMetadata.AdditionalValues.ContainsKey(nameof(FWDatasourceAttribute))) { FWTableColumn column = CreateColumn(itemMetadata, prop); column.Property = prop; Columns.Add(column); } } }
/// <summary> /// Adds a custom column to the table. /// </summary> /// <param name="column">The column object.</param> protected void AddColumn(FWTableColumn column) { Columns.Add(column); }