-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
DataGrid: Prefer DatePicker DataGridDateEditColumn and add public API #5719
Open
David-Moreira
wants to merge
5
commits into
master
Choose a base branch
from
5717-datagrid-datagrideditcolumn-prefer-datepicker-add-dateinputmode-public-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c40a90
DataGrid | Prefer DatePicker over DateEdit for DateColumn | Propagate…
David-Moreira e00b3c3
Release notes
David-Moreira 8f02e3b
DateGridDateColumn | NativeInputMode
David-Moreira 5290fb8
DataGridNumericColumn | NativeInputMode
David-Moreira b462a90
merge master
David-Moreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
Source/Extensions/Blazorise.DataGrid/_DataGridCellDateEdit.razor
This file was deleted.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
Source/Extensions/Blazorise.DataGrid/_DataGridCellDatePicker.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
@using Blazorise.Utilities | ||
@typeparam TItem | ||
@inherits ComponentBase | ||
|
||
@if ( TypeHelper.IsDate( valueType ) ) | ||
{ | ||
@if ( Column.NativeInputMode ) | ||
{ | ||
@dateEditFragment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a small note. Make it uppercase so it matches the naming for numeric component, |
||
} | ||
else | ||
{ | ||
@datePickerFragment | ||
} | ||
} | ||
|
||
@code { | ||
private RenderFragment datePickerFragment => builder => | ||
{ | ||
var type = typeof( DatePicker<> ).MakeGenericType( new[] { valueType } ); | ||
|
||
builder.OpenComponent( 0, type ); | ||
builder.AddAttribute( 1, nameof( DatePicker<object>.Date ), valueType switch | ||
{ | ||
Type typeDateTime when typeDateTime == typeof( DateTime ) => (DateTime)( CellValue ?? (DateTime)default ), | ||
Type typeDateTimeNull when typeDateTimeNull == typeof( DateTime? ) => (DateTime?)( CellValue ?? (DateTime?)default ), | ||
Type typeDateOnly when typeDateOnly == typeof( DateOnly ) => (DateOnly)( CellValue ?? (DateOnly)default ), | ||
Type typeDateOnlyNull when typeDateOnlyNull == typeof( DateOnly? ) => (DateOnly?)( CellValue ?? (DateOnly?)default ), | ||
Type typeDateTimeOffset when typeDateTimeOffset == typeof( DateTimeOffset ) => (DateTimeOffset)( CellValue ?? (DateTimeOffset)default ), | ||
Type typeDateTimeOffsetNull when typeDateTimeOffsetNull == typeof( DateTimeOffset? ) => (DateTimeOffset?)( CellValue ?? (DateTimeOffset?)default ), | ||
_ => throw new InvalidOperationException( $"Unsupported type {valueType}" ) | ||
} ); | ||
builder.AddAttribute( 2, nameof( DatePicker<object>.DateChanged ), valueType switch | ||
{ | ||
Type typeDateTime when typeDateTime == typeof( DateTime ) => EventCallback.Factory.Create<DateTime>( this, ( OnCellValueChanged<DateTime> ) ), | ||
Type typeDateTimeNull when typeDateTimeNull == typeof( DateTime? ) => EventCallback.Factory.Create<DateTime?>( this, ( OnCellValueChanged<DateTime?> ) ), | ||
Type typeDateOnly when typeDateOnly == typeof( DateOnly ) => EventCallback.Factory.Create<DateOnly>( this, ( OnCellValueChanged<DateOnly> ) ), | ||
Type typeDateOnlyNull when typeDateOnlyNull == typeof( DateOnly? ) => EventCallback.Factory.Create<DateOnly?>( this, ( OnCellValueChanged<DateOnly?> ) ), | ||
Type typeDateTimeOffset when typeDateTimeOffset == typeof( DateTimeOffset ) => EventCallback.Factory.Create<DateTimeOffset>( this, ( OnCellValueChanged<DateTimeOffset> ) ), | ||
Type typeDateTimeOffsetNull when typeDateTimeOffsetNull == typeof( DateTimeOffset? ) => EventCallback.Factory.Create<DateTimeOffset?>( this, ( OnCellValueChanged<DateTimeOffset?> ) ), | ||
_ => throw new InvalidOperationException( $"Unsupported type {valueType}" ) | ||
} ); | ||
builder.AddAttribute( 3, nameof( BaseInputComponent<object>.ReadOnly ), Column.Readonly ); | ||
builder.AddAttribute( 4, nameof( DatePicker<object>.Pattern ), Column.ValidationPattern ); | ||
builder.AddAttribute( 5, nameof( DatePicker<object>.InputMode ), Column.InputMode ); | ||
builder.AddAttribute( 6, nameof( DatePicker<object>.Min ), Column.Min ); | ||
builder.AddAttribute( 7, nameof( DatePicker<object>.Max ), Column.Max ); | ||
builder.AddAttribute( 8, nameof( DatePicker<object>.FirstDayOfWeek ), Column.FirstDayOfWeek ); | ||
builder.AddAttribute( 9, nameof( DatePicker<object>.InputFormat ), Column.InputFormat ); | ||
builder.AddAttribute( 10, nameof( DatePicker<object>.DisabledDates ), Column.DisabledDates ); | ||
builder.AddAttribute( 11, nameof( DatePicker<object>.DisabledDays ), Column.DisabledDays ); | ||
builder.AddAttribute( 12, nameof( DatePicker<object>.Inline ), Column.Inline ); | ||
builder.AddAttribute( 13, nameof( DatePicker<object>.DisableMobile ), Column.DisableMobile ); | ||
builder.AddAttribute( 14, nameof( DatePicker<object>.StaticPicker ), Column.StaticPicker ); | ||
builder.AddAttribute( 15, nameof( DatePicker<object>.DisplayFormat ), Column.DateDisplayFormat ); | ||
builder.CloseComponent(); | ||
}; | ||
|
||
private RenderFragment dateEditFragment => builder => | ||
{ | ||
var type = typeof( DateEdit<> ).MakeGenericType( new[] { valueType } ); | ||
|
||
builder.OpenComponent( 0, type ); | ||
builder.AddAttribute( 1, nameof( DateEdit<object>.Date ), valueType switch | ||
{ | ||
Type typeDateTime when typeDateTime == typeof( DateTime ) => (DateTime)( CellValue ?? (DateTime)default ), | ||
Type typeDateTimeNull when typeDateTimeNull == typeof( DateTime? ) => (DateTime?)( CellValue ?? (DateTime?)default ), | ||
Type typeDateOnly when typeDateOnly == typeof( DateOnly ) => (DateOnly)( CellValue ?? (DateOnly)default ), | ||
Type typeDateOnlyNull when typeDateOnlyNull == typeof( DateOnly? ) => (DateOnly?)( CellValue ?? (DateOnly?)default ), | ||
Type typeDateTimeOffset when typeDateTimeOffset == typeof( DateTimeOffset ) => (DateTimeOffset)( CellValue ?? (DateTimeOffset)default ), | ||
Type typeDateTimeOffsetNull when typeDateTimeOffsetNull == typeof( DateTimeOffset? ) => (DateTimeOffset?)( CellValue ?? (DateTimeOffset?)default ), | ||
_ => throw new InvalidOperationException( $"Unsupported type {valueType}" ) | ||
} ); | ||
builder.AddAttribute( 2, nameof( DateEdit<object>.DateChanged ), valueType switch | ||
{ | ||
Type typeDateTime when typeDateTime == typeof( DateTime ) => EventCallback.Factory.Create<DateTime>( this, ( OnCellValueChanged<DateTime> ) ), | ||
Type typeDateTimeNull when typeDateTimeNull == typeof( DateTime? ) => EventCallback.Factory.Create<DateTime?>( this, ( OnCellValueChanged<DateTime?> ) ), | ||
Type typeDateOnly when typeDateOnly == typeof( DateOnly ) => EventCallback.Factory.Create<DateOnly>( this, ( OnCellValueChanged<DateOnly> ) ), | ||
Type typeDateOnlyNull when typeDateOnlyNull == typeof( DateOnly? ) => EventCallback.Factory.Create<DateOnly?>( this, ( OnCellValueChanged<DateOnly?> ) ), | ||
Type typeDateTimeOffset when typeDateTimeOffset == typeof( DateTimeOffset ) => EventCallback.Factory.Create<DateTimeOffset>( this, ( OnCellValueChanged<DateTimeOffset> ) ), | ||
Type typeDateTimeOffsetNull when typeDateTimeOffsetNull == typeof( DateTimeOffset? ) => EventCallback.Factory.Create<DateTimeOffset?>( this, ( OnCellValueChanged<DateTimeOffset?> ) ), | ||
_ => throw new InvalidOperationException( $"Unsupported type {valueType}" ) | ||
} ); | ||
builder.AddAttribute( 3, nameof( BaseInputComponent<object>.ReadOnly ), Column.Readonly ); | ||
builder.AddAttribute( 4, nameof( DateEdit<object>.Pattern ), Column.ValidationPattern ); | ||
builder.AddAttribute( 5, nameof( DateEdit<object>.InputMode ), Column.InputMode ); | ||
builder.AddAttribute( 6, nameof( DateEdit<object>.Min ), Column.Min ); | ||
builder.AddAttribute( 7, nameof( DateEdit<object>.Max ), Column.Max ); | ||
builder.CloseComponent(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reuse the
DisplayFormat
fromBaseDataGridColumn
? It is the same thing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, although this would have the advantage that you could have a different display format (when viewing the table) and edit format (when editing the records)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past this DisplayFormat was used on DateEdit. Back then, DateEdit was using some JS for formating. So it makes sense to make it used on DatePicker today.