public WebBaseGrid <TModel> GenerateCheckedColumn(bool genCheckedColumn = true) { this.GenCheckedColumn = genCheckedColumn; if (genCheckedColumn) { WebGridColumn col = new WebGridColumn("Select", CommonData.StringEmpty, true); this.GridColumns.Insert(0, col); } return(this); }
public WebGridColumn Column(string columnName = null, string header = null, Func <T, object> format = null, string style = null, bool canSort = true) { Func <dynamic, object> wrappedFormat = null; if (format != null) { wrappedFormat = o => format((T)o.Value); } WebGridColumn column = base.Column(columnName, header, wrappedFormat, style, canSort); return(column); }
public WebGridColumn Add <TColumn>(Expression <Func <TModel, TColumn> > expression) { string name = ExpressionHelper.GetExpressionText(expression); var metadata = ModelMetadataProviders.Current.GetMetadataForProperty(() => Activator.CreateInstance <TModel>(), typeof(TModel), name); var text = CommonMethod.IsNullOrEmpty(metadata.DisplayName) ? metadata.PropertyName : metadata.DisplayName; WebGridColumn col = new WebGridColumn(base.Helper, name, text); this.GridColumns.Add(col); return(col); }
public GridColumnOrder(int Index, WebGridColumn Column) { this.Index = Index; this.Column = Column; }
public static List <WebGridColumn> ObtenerColumna(this HtmlHelper htmlHelper, List <WebGridColumn> Columnas, WebGridColumn columna, bool validarColumna = false, string controlador = "", string accion = "", List <Accion> Acciones = null) { //Se verifica si se debe de validar los permisos if (validarColumna) { if (Acciones != null || Acciones.Count != 0) { //se obtiene el cont controlador = controlador.Replace("Controller", string.Empty).Trim(); if (Acciones.Any(a => a.Controlador == controlador && a.Nombre == accion)) { Columnas.Add(columna); } } } else { Columnas.Add(columna); } return(Columnas); }
public static IHtmlString Table <TModel, TRowType>(this HtmlHelper <TModel> html, IEnumerable <TRowType> rows, string targetId, out WebGrid grid, object htmlAttributes = null, string fieldNamePrefix = null, string ajaxUpdateCallbackFunction = null, params WebGridColumn[] commandColumns) { ModelMetadata rowMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TRowType)); List <WebGridColumn> columns = rowMetadata.Properties .Where(p => p.ShowForDisplay) .Select(p => { WebGridColumn col = new WebGridColumn { ColumnName = p.PropertyName, Header = p.DisplayName, CanSort = true }; if (p.DataTypeName == DataType.Currency.ToString() || p.ModelType.IsAssignableFrom(typeof(decimal)) || p.ModelType.IsAssignableFrom(typeof(double)) || p.ModelType.IsAssignableFrom(typeof(int))) { // if (p.ModelType.IsAssignableFrom(typeof(int)) || p.ModelType.IsAssignableFrom(typeof(int?))) col.Style = "right-cell"; } else if (p.DataTypeName == DataType.Date.ToString() || p.DataTypeName == DataType.DateTime.ToString()) { col.Style = "center-cell"; } //PropertyInfo propertyInfo = p.ContainerType.GetProperty(p.PropertyName); LinkAttribute linkAttribute = p.ContainerType.GetProperty(p.PropertyName).GetCustomAttributes(true).OfType <LinkAttribute>().FirstOrDefault(); if (linkAttribute != null) { // (string)getPropertyValue(p, item) -> ((object)getPropertyValue(p, item)).ToString() col.Format = (item) => { RouteValueDictionary routeValueDictionary = new RouteValueDictionary(); PropertyInfo valuePropertyInfo = p.ContainerType.GetProperty(linkAttribute.FieldId); dynamic idValue = valuePropertyInfo.GetValue((item as WebGridRow).Value); string text = (string)getPropertyValue(p, item); if (idValue != null) { routeValueDictionary.Add(linkAttribute.IdParamName, /* valuePropertyInfo.GetValue((item as WebGridRow).Value) */ idValue); return(html.ActionLink(/*(string)getPropertyValue(p, item)*/ text, linkAttribute.ActionName, linkAttribute.ControllerName, routeValueDictionary, null)); } else { return(text); } }; } if (!string.IsNullOrEmpty(p.DisplayFormatString)) { col.Format = (item) => string.Format(p.DisplayFormatString, /* Utils.GetPropValue(item, p.PropertyName) */ arg0: getPropertyValue(p, item)); } else if (p.ModelType.IsAssignableFrom(typeof(bool))) { col.Format = (item) => html.Raw("<input type='checkbox' " + ((getPropertyValue(p, item) == true) ? "checked" : "") + " disabled='disabled' />"); col.Style = "center-cell"; } return(col); }).ToList(); if (commandColumns != null) { columns.AddRange(commandColumns); } grid = new WebGrid(rows as IEnumerable <dynamic>, ajaxUpdateContainerId: targetId, ajaxUpdateCallback: ajaxUpdateCallbackFunction, fieldNamePrefix: fieldNamePrefix, selectionFieldName: "SelectedRow"); string className = "table table-bordered table-striped"; return(grid.GetHtml(tableStyle: className, columns: columns, htmlAttributes: htmlAttributes)); }