You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The values of the properties in the grid are retrieved directly from the database models (from db) and displayed as they are.
There is no easy way to override this behavior and make transformations to the data.
For example in Judge we need to modify date fields, to convert from one time zone to another when displaying the values in the grid.
Currently we have implemented a workaround by overriding BuildGridColumns:
var gridColumns = base.BuildGridColumns(columns, stringMaxLength);
// Convert DateTime values to local time before displaying, as the admins will be working with local time,
// but in the database are always stored in UTC.
// TODO: provide option to override a method that just generates the expression that gets the property value.
// This is a workaround, but if option to override the method that gets the lambda is provided,
// in the AutoCrudAdminOptions (GenerateColumnConfiguration), it will be much easier to just override the expression.
gridColumns.ForEach(gc =>
{
var propertyInfo = typeof(TEntity).GetProperty(gc.Name);
if (propertyInfo == null || !TypeIsDateTime(propertyInfo.PropertyType))
{
return;
}
gridColumns.Remove(gc);
if (gc is IGridColumn<TEntity, DateTime> dateTimeGridColumn)
{
gridColumns
.Add(
this.GetDateTimeToLocalExpression<DateTime>(propertyInfo)
?? dateTimeGridColumn.Expression)
.Titled(propertyInfo.Name)
.Filterable(true)
.Sortable(true);
}
else if (gc is IGridColumn<TEntity, DateTime?> nullableDateTimeGridColumn)
{
gridColumns
.Add(
this.GetDateTimeToLocalExpression<DateTime?>(propertyInfo)
?? nullableDateTimeGridColumn.Expression)
.Titled(propertyInfo.Name)
.Filterable(true)
.Sortable(true);
}
});
return gridColumns;
Proposed easy solution:
It would be much easier if we can override just the part where the lambda is generated in AutoCrudAdminController's GenerateColumnConfiguration:
var lambda = ExpressionsBuilder.ForGetProperty<TEntity, TProperty>(property);
This could become:
var lambda = GenerateColumnLambda(property);
where GenerateColumnLambda(property) is virtual method.
We would not have to remove columns and create new ones.
NOTE: with this solution, expression trees will also have to be created by the users of the library, but at least no knowledge of columns generation will be needed.
The text was updated successfully, but these errors were encountered:
The problem
The values of the properties in the grid are retrieved directly from the database models (from db) and displayed as they are.
There is no easy way to override this behavior and make transformations to the data.
For example in Judge we need to modify date fields, to convert from one time zone to another when displaying the values in the grid.
Currently we have implemented a workaround by overriding
BuildGridColumns
:Proposed easy solution:
It would be much easier if we can override just the part where the lambda is generated in
AutoCrudAdminController
'sGenerateColumnConfiguration
:This could become:
where
GenerateColumnLambda(property)
is virtual method.We would not have to remove columns and create new ones.
NOTE: with this solution, expression trees will also have to be created by the users of the library, but at least no knowledge of columns generation will be needed.
The text was updated successfully, but these errors were encountered: