Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGridSelectColumn: SetValue, consider ValueField if set #5080

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 additions & 0 deletions Source/Extensions/Blazorise.DataGrid/DataGridSelectColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ 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
Loading