Skip to content

Commit

Permalink
DataGridSelectColumn | SetValue, consider ValueField if set
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Moreira committed Oct 17, 2023
1 parent 4ce93da commit c8de1f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Source/Extensions/Blazorise.DataGrid/DataGridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public partial class DataGridColumn<TItem> : BaseDataGridColumn<TItem>
{
#region Members

private readonly Lazy<Func<Type>> valueTypeGetter;
private readonly Lazy<Func<object>> defaultValueByType;
private readonly Lazy<Func<TItem, object>> valueGetter;
private readonly Lazy<Action<TItem, object>> valueSetter;
private readonly Lazy<Func<TItem, object>> sortFieldGetter;
protected readonly Lazy<Func<Type>> valueTypeGetter;
protected readonly Lazy<Func<object>> defaultValueByType;
protected readonly Lazy<Func<TItem, object>> valueGetter;
protected readonly Lazy<Action<TItem, object>> valueSetter;
protected readonly Lazy<Func<TItem, object>> sortFieldGetter;

private Dictionary<DataGridSortMode, SortDirection> currentSortDirection { get; set; } = new();

Expand Down Expand Up @@ -110,7 +110,7 @@ internal object GetDefaultValueByType()
/// </summary>
/// <param name="item">Item for which to get the value.</param>
/// <returns></returns>
internal object GetValue( TItem item )
protected internal object GetValue( TItem item )
=> !string.IsNullOrEmpty( Field )
? valueGetter.Value( item )
: default;
Expand All @@ -120,7 +120,7 @@ internal object GetValue( TItem item )
/// </summary>
/// <param name="item">Item for which to set the value.</param>
/// <param name="value">Value to set.</param>
internal void SetValue( TItem item, object value )
protected internal virtual void SetValue( TItem item, object value )
{
if ( !string.IsNullOrEmpty( Field ) )
valueSetter.Value( item, value );
Expand All @@ -131,7 +131,7 @@ internal void SetValue( TItem item, object value )
/// </summary>
/// <param name="item">Item for which to get the value.</param>
/// <returns></returns>
internal object GetSortValue( TItem item )
protected internal object GetSortValue( TItem item )
=> sortFieldGetter.Value( item );

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions Source/Extensions/Blazorise.DataGrid/DataGridSelectColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ public class DataGridSelectColumn<TItem> : DataGridColumn<TItem>
{
public override DataGridColumnType ColumnType => DataGridColumnType.Select;

//<inheritdoc/>
protected internal override void SetValue( TItem item, object value )
{
if ( !string.IsNullOrEmpty( Field ) )
if ( ValueField is null )
valueSetter.Value( item, value );
else
valueSetter.Value( item, ValueField( value ) );
}

/// <summary>
/// Gets or sets the select data-source.
/// </summary>
Expand Down

0 comments on commit c8de1f5

Please sign in to comment.