-
-
Notifications
You must be signed in to change notification settings - Fork 364
feat(RadioListGeneric): support generic SelectedItem #4859
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f54df9e
Update ITableColumnExtensions.cs
handesoft 7be8d98
Update ITableColumnExtensions.cs
handesoft 7c8c3e3
Merge branch 'main' into dev-tiansfather
ArgoZhang 3f7feb1
refactor: 增加 Key 关键字
ArgoZhang 42478be
feat: 增加 CheckboxGeneric 组件
ArgoZhang 421c479
Merge branch 'main' into doc-radio-list
ArgoZhang 90b5376
refactor: 更新泛型 CheckboxList 组件
ArgoZhang 7141422
doc: 更新示例文档
ArgoZhang d9cd96f
Merge branch 'main' into doc-radio-list
ArgoZhang 8ad21d1
test: 增加单元测试
ArgoZhang 6d8878e
feat: 增加 CheckboxListGeneric 组件
ArgoZhang e8c7620
test: 增加单元测试
ArgoZhang 47268ea
Merge branch 'test-pr' into dev-tiansfather
ArgoZhang 5d5685f
Merge branch 'main' into dev-tiansfather
ArgoZhang d50f3c0
refactor: 精简代码
ArgoZhang cb8a7e2
revert: 撤销更新
ArgoZhang e3232d1
refactor: 增加可为空标记
ArgoZhang 1b03d0c
feat: 增加 RadioListGeneric 组件
ArgoZhang 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| using System.Collections; | ||
| using System.Globalization; | ||
|
|
||
| namespace BootstrapBlazor.Components; | ||
|
|
@@ -174,15 +175,46 @@ | |
|
|
||
| internal static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem item) => async builder => | ||
| { | ||
| // 1.增加了一个从IEnumerable转化为List<object>方法 | ||
| Func<IEnumerable, List<object>> GetEnumeratorDatas = (enumerableObj) => | ||
| { | ||
| var enumerator = enumerableObj.GetEnumerator(); | ||
| var list = new List<object>(); | ||
| while (enumerator.MoveNext()) | ||
| { | ||
| list.Add(enumerator.Current); | ||
| } | ||
| return list; | ||
| }; | ||
|
|
||
| var val = col.GetItemValue(item); | ||
| if (col.Lookup != null && val != null) | ||
| { | ||
| string? content = val.ToString(); | ||
| // 转化 Lookup 数据源 | ||
| var lookupVal = col.Lookup.FirstOrDefault(l => l.Value.Equals(val.ToString(), col.LookupStringComparison)); | ||
| if (lookupVal != null) | ||
| if ((Nullable.GetUnderlyingType(col.PropertyType) ?? col.PropertyType).IsGenericType && val is IEnumerable v) | ||
ArgoZhang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| builder.AddContent(10, col.RenderTooltip(lookupVal.Text, item)); | ||
| // 2.如果是 IEnumerable 类型,则转化为 List<object> 类型 然后根据 List<object> 类型进行 Lookup 匹配 | ||
| var enumeratorDatas = GetEnumeratorDatas(v); | ||
| var lookupVals = col.Lookup.Where(l => enumeratorDatas.Any(v1 => l.Value.Equals(v1?.ToString(), col.LookupStringComparison))); | ||
| if (lookupVals.Any()) | ||
| { | ||
| content = string.Join(",", lookupVals.Select(l => l.Text)); | ||
| } | ||
| else | ||
| { | ||
| content = string.Join(",", enumeratorDatas); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| var lookupVal = col.Lookup.FirstOrDefault(l => l.Value.Equals(val.ToString(), col.LookupStringComparison)); | ||
| if (lookupVal != null) | ||
| { | ||
| content = lookupVal.Text; | ||
| } | ||
| } | ||
| builder.AddContent(10, col.RenderTooltip(content, item)); | ||
| } | ||
| else if (val is bool v1) | ||
| { | ||
|
|
@@ -205,9 +237,14 @@ | |
| { | ||
| content = Utility.Format(val, CultureInfo.CurrentUICulture.DateTimeFormat); | ||
| } | ||
| else if (val is IEnumerable<object> v) | ||
| //else if(val is IEnumerable<object> v) | ||
| //{ | ||
| // content = string.Join(",", v); | ||
| //} | ||
| //3.这里的判断条件调整了一下,为了支持List<int>,List<string> 等等 | ||
| else if ((Nullable.GetUnderlyingType(col.PropertyType) ?? col.PropertyType).IsGenericType && val is IEnumerable v) | ||
| { | ||
| content = string.Join(",", v); | ||
| content = string.Join(",", GetEnumeratorDatas(v)); | ||
| } | ||
| else | ||
| { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.