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

feat(Table): add IsVisibleWhenAdd/Edit parameter #2938

Merged
merged 23 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
54 changes: 35 additions & 19 deletions src/BootstrapBlazor.Server/Components/Samples/Table/Tables.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ private void OnClick()
Items = Foo.GenerateFoo(FooLocalizer);
}

private IEnumerable<AttributeItem> GetTableColumnAttributes() => new AttributeItem[]
{
private AttributeItem[] GetTableColumnAttributes() =>
[
new()
{
Name = "TextWrap",
Expand Down Expand Up @@ -113,22 +113,6 @@ private void OnClick()
DefaultValue = " — "
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenAdd),
Description = Localizer["IsReadonlyWhenAddAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenEdit),
Description = Localizer["IsReadonlyWhenEditAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.Lookup),
Description = Localizer["LookupAttr"],
Expand Down Expand Up @@ -169,6 +153,22 @@ private void OnClick()
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenAdd),
Description = Localizer["IsReadonlyWhenAddAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = nameof(IEditorItem.IsReadonlyWhenEdit),
Description = Localizer["IsReadonlyWhenEditAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "false"
},
new()
{
Name = "SearchTemplate",
Description = Localizer["SearchTemplateColumnAttr"],
Expand Down Expand Up @@ -257,6 +257,22 @@ private void OnClick()
DefaultValue = "true"
},
new()
{
Name = "IsVisibleWhenAdd",
Description = Localizer["IsVisibleWhenAddAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "true"
},
new()
{
Name = "IsVisibleWhenEdit",
Description = Localizer["IsVisibleWhenEditAttr"],
Type = "boolean",
ValueList = "true|false",
DefaultValue = "true"
},
new()
{
Name = "Width",
Description = Localizer["WidthAttr"],
Expand Down Expand Up @@ -344,7 +360,7 @@ private void OnClick()
ValueList = "true/false",
DefaultValue = "false"
}
};
];

private AttributeItem[] GetAttributes() =>
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
<h3>@Localizer["TablesEditTitle"]</h3>
<h4>@((MarkupString)Localizer["TablesEditDescription"].Value)</h4>

<DemoBlock Title="@Localizer["TablesEditItemsTitle"]"
Introduction="@Localizer["TablesEditItemsIntro"]"
Name="EditItems">
<DemoBlock Title="@Localizer["TablesEditItemsTitle"]" Introduction="@Localizer["TablesEditItemsIntro"]" Name="EditItems">
<section ignore>@((MarkupString)Localizer["TablesEditItemsDescription"].Value)</section>
<Table TItem="Foo" @bind-Items="EditItems"
IsStriped="true" IsBordered="true" IsMultipleSelect="true"
Expand All @@ -26,9 +24,21 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditTemplateTitle"]"
Introduction="@Localizer["TablesEditTemplateIntro"]"
Name="EditTemplate">
<DemoBlock Title="@Localizer["TablesVisibleTitle"]" Introduction="@Localizer["TablesVisibleIntro"]" Name="Visible">
<Table TItem="Foo" Items="@Items.Take(3)" IsMultipleSelect="true"
ShowToolbar="true" ShowExtendButtons="true">
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
<TableColumn @bind-Field="@context.Address" Rows="3" Visible="false" IsVisibleWhenAdd="true" IsVisibleWhenEdit="true" />
<TableColumn @bind-Field="@context.Count" IsVisibleWhenAdd="false" />
<TableColumn @bind-Field="@context.Complete" IsVisibleWhenEdit="false" />
<TableColumn @bind-Field="@context.Education" />
</TableColumns>
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditTemplateTitle"]" Introduction="@Localizer["TablesEditTemplateIntro"]" Name="EditTemplate">
<section ignore>@((MarkupString)Localizer["TablesEditTemplateDescription"].Value)</section>
<Table TItem="Foo" EditDialogShowMaximizeButton="true"
IsPagination="true" PageItemsSource="@PageItemsSource" DataService="@CustomerDataService"
Expand All @@ -51,9 +61,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditOnAddAsyncTitle"]"
Introduction="@Localizer["TablesEditOnAddAsyncIntro"]"
Name="OnAddAsync">
<DemoBlock Title="@Localizer["TablesEditOnAddAsyncTitle"]" Introduction="@Localizer["TablesEditOnAddAsyncIntro"]" Name="OnAddAsync">
<section ignore>
<p>@((MarkupString)Localizer["TablesEditOnAddAsyncDescription"].Value)</p>
<p>@((MarkupString)Localizer["TablesEditOnAddAsyncTips1"].Value)</p>
Expand All @@ -80,9 +88,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesColumnEditTemplateTitle"]"
Introduction="@Localizer["TablesColumnEditTemplateIntro"]"
Name="ColumnEditTemplate">
<DemoBlock Title="@Localizer["TablesColumnEditTemplateTitle"]" Introduction="@Localizer["TablesColumnEditTemplateIntro"]" Name="ColumnEditTemplate">
<section ignore>
<div>@((MarkupString)Localizer["TablesColumnEditTemplateDescription1"].Value)</div>
<div>@((MarkupString)Localizer["TablesColumnEditTemplateTips"].Value)</div>
Expand All @@ -109,9 +115,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditModeTitle"]"
Introduction="@Localizer["TablesEditModeIntro"]"
Name="EditMode">
<DemoBlock Title="@Localizer["TablesEditModeTitle"]" Introduction="@Localizer["TablesEditModeIntro"]" Name="EditMode">
<section ignore>
<p>@((MarkupString)Localizer["TablesEditModeDescription"].Value)</p>
<p>@((MarkupString)Localizer["TablesEditModeTips1"].Value)</p>
Expand All @@ -127,18 +131,17 @@
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
<TableColumn @bind-Field="@context.Address" />
<TableColumn @bind-Field="@context.Address" Rows="3" />
<TableColumn @bind-Field="@context.Education" />
<TableColumn @bind-Field="@context.Count" />
<TableColumn @bind-Field="@context.Complete" />
<TableColumn @bind-Field="@context.Count" IsVisibleWhenAdd="false" />
<TableColumn @bind-Field="@context.Complete" IsVisibleWhenEdit="false" />
</TableColumns>
</Table>

<section ignore>
<p>@((MarkupString)Localizer["TablesEditModeInCell"].Value)</p>
<RadioList @bind-Value="InsertMode" />
</section>

<Table TItem="Foo"
IsPagination="true" PageItemsSource="@PageItemsSource"
IsStriped="true" IsBordered="true" IsMultipleSelect="true"
Expand All @@ -148,17 +151,15 @@
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" />
<TableColumn @bind-Field="@context.Name" />
<TableColumn @bind-Field="@context.Address" />
<TableColumn @bind-Field="@context.Address" Rows="3" />
<TableColumn @bind-Field="@context.Education" />
<TableColumn @bind-Field="@context.Count" />
<TableColumn @bind-Field="@context.Complete" />
<TableColumn @bind-Field="@context.Count" IsVisibleWhenAdd="false" />
<TableColumn @bind-Field="@context.Complete" IsVisibleWhenEdit="false" />
</TableColumns>
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditInjectDataServiceTitle"]"
Introduction="@Localizer["TablesEditInjectDataServiceIntro"]"
Name="InjectDataService">
<DemoBlock Title="@Localizer["TablesEditInjectDataServiceTitle"]" Introduction="@Localizer["TablesEditInjectDataServiceIntro"]" Name="InjectDataService">
<section ignore>
@((MarkupString)Localizer["TablesEditInjectDataServiceDescription"].Value)
<ul class="ul-demo mb-3">
Expand All @@ -182,9 +183,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditDataServiceTitle"]"
Introduction="@Localizer["TablesEditDataServiceIntro"]"
Name="DataService">
<DemoBlock Title="@Localizer["TablesEditDataServiceTitle"]" Introduction="@Localizer["TablesEditDataServiceIntro"]" Name="DataService">
<section ignore>
<b>@Localizer["TablesEditDataServiceDescription"]</b>
<div class="mt-1">@((MarkupString)Localizer["TablesEditDataServiceTips1"].Value)</div>
Expand All @@ -201,9 +200,7 @@
</Table>
</DemoBlock>

<DemoBlock Title="@Localizer["TablesEditFooterTemplateTitle"]"
Introduction="@Localizer["TablesEditFooterTemplateIntro"]"
Name="EditFooterTemplate">
<DemoBlock Title="@Localizer["TablesEditFooterTemplateTitle"]" Introduction="@Localizer["TablesEditFooterTemplateIntro"]" Name="EditFooterTemplate">
<section ignore>
<p>@((MarkupString)Localizer["TablesEditFooterTemplateDescription"].Value)</p>
<Pre class="mb-3">&lt;EditFooterTemplate Context="model"&gt;
Expand Down
6 changes: 5 additions & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4823,6 +4823,8 @@
"TextEllipsisAttr": "Whether to omit text when exceeded",
"TemplateAttr": "Template",
"VisibleAttr": "Whether to display this column",
"IsVisibleWhenAddAttr": "Whether to display this column in new item dialog",
"IsVisibleWhenEditAttr": "Whether to display this column in edit item dialog",
"WidthAttr": "Column width (px)",
"FixedAttr": "Whether to fix this column",
"GroupNameAttr": "Current Property Grouping",
Expand Down Expand Up @@ -4998,7 +5000,9 @@
"TablesEditInjectDataServiceTips1": "Startup file injects data service",
"TablesEditInjectDataServiceTips2": "Implementation principle and usage introduction",
"TablesEditInjectDataServiceTips3": "custom data service",
"TablesEditInjectDataServiceTips4": "After enabling the use of the injected data service, you can set the component individually by setting the <code>DataServices</code> parameter, if the instance provided by the internal use of the injected service is not set"
"TablesEditInjectDataServiceTips4": "After enabling the use of the injected data service, you can set the component individually by setting the <code>DataServices</code> parameter, if the instance provided by the internal use of the injected service is not set",
"TablesVisibleNormalTitle": "Editor Visible/Hidden",
"TablesVisibleNormalIntro": "If the <code>IsVisibleWhenAdd</code> or <code>IsVisibleWhenEdit</code> property is set to <code>false</code>, hide this column when creating or updating. In this example, the <b>New</b> pop-up window does not display <b>Count</b> <b>Edit</b> Pop up window does not display <b>Complete</b> edit the item"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesVirtualization": {
"TablesVirtualizationTitle": "Table virtual scroll row",
Expand Down
6 changes: 5 additions & 1 deletion src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -4823,6 +4823,8 @@
"TextEllipsisAttr": "是否文本超出时省略",
"TemplateAttr": "模板",
"VisibleAttr": "是否显示此列",
"IsVisibleWhenAddAttr": "新建时此列是否显示",
"IsVisibleWhenEditAttr": "编辑时此列是否显示",
"WidthAttr": "列宽度(像素px)",
"FixedAttr": "是否固定本列",
"GroupNameAttr": "当前属性分组",
Expand Down Expand Up @@ -4998,7 +5000,9 @@
"TablesEditInjectDataServiceTips2": "实现原理与用法介绍",
"TablesEditInjectDataServiceTips3": "自定义数据服务",
"TablesEditInjectDataServiceTips4": "开启使用注入数据服务后,可通过设置 <code>DataServices</code> 参数对组件进行单独设置,如未设置内部使用注入服务提供的实例",
"TablesEditShowSearchPlaceHolderString": "不可为空,50字以内"
"TablesEditShowSearchPlaceHolderString": "不可为空,50字以内",
"TablesVisibleTitle": "Table 编辑时显示/隐藏",
"TablesVisibleIntro": "<div><code>Visible</code> 默认值为 <code>true</code> 如果有列设置了 <code>IsVisibleWhenAdd</code> 或者 <code>IsVisibleWhenEdit</code> 属性为 <code>false</code> 时, 新建或者更新时隐藏此列。本例中 <b>新建</b> 弹窗不显示 <b>数量</b> <b>编辑</b> 弹窗不显示 <b>是否</b> 编辑项。</div><div>可以通过在数据模型中使用 <code>[AutoGenerateClass(Visible = false)]</code> 全部禁止显示,再通过 <code>IsVisibleWhenAdd</code> 或者 <code>IsVisibleWhenEdit</code> 单独设置编辑状态下的可见性,本例中,<b>地址</b> 列默认不可见,<b>新建、编辑</b> 弹窗内均可以编辑</div>"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesVirtualization": {
"TablesVirtualizationTitle": "Table 虚拟滚动行",
Expand Down
9 changes: 7 additions & 2 deletions src/BootstrapBlazor/Attributes/AutoGenerateBaseAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BootstrapBlazor.Components;

/// <summary>
///
/// AutoGenerateColumn 标签基类,用于 <see cref="Table{TItem}"/> 标识自动生成列
/// </summary>
public abstract class AutoGenerateBaseAttribute : Attribute
{
Expand All @@ -15,10 +15,15 @@ public abstract class AutoGenerateBaseAttribute : Attribute
public bool Editable { get; set; } = true;

/// <summary>
/// 获得/设置 当前列编辑时是否只读 默认为 false
/// 获得/设置 当前编辑项是否只读 默认为 false
/// </summary>
public bool Readonly { get; set; }

/// <summary>
/// 获得/设置 当前编辑项是否显示 默认为 true
/// </summary>
public bool Visible { get; set; } = true;

/// <summary>
/// 获得/设置 是否允许排序 默认为 false
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BootstrapBlazor.Components;

/// <summary>
///
/// AutoGenerateColumn 标签类,用于 <see cref="Table{TItem}"/> 标识自动生成列
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class AutoGenerateClassAttribute : AutoGenerateBaseAttribute
Expand Down
19 changes: 12 additions & 7 deletions src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,25 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
public bool SkipValidate { get; set; }

/// <summary>
/// 获得/设置 新建时此列只读 默认为 false
/// <inheritdoc/>
/// </summary>
public bool IsReadonlyWhenAdd { get; set; }

/// <summary>
/// 获得/设置 编辑时此列只读 默认为 false
/// <inheritdoc/>
/// </summary>
public bool IsReadonlyWhenEdit { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool IsVisibleWhenAdd { get; set; } = true;

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool IsVisibleWhenEdit { get; set; } = true;

/// <summary>
/// 获得/设置 是否显示标签 Tooltip 多用于标签文字过长导致裁减时使用 默认 false
/// </summary>
Expand Down Expand Up @@ -80,11 +90,6 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
/// </summary>
public bool Fixed { get; set; }

/// <summary>
/// 获得/设置 列是否显示 默认为 true 可见的
/// </summary>
public bool Visible { get; set; } = true;

/// <summary>
/// 获得/设置 列 td 自定义样式 默认为 null 未设置
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/Components/EditorForm/EditorForm.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<CascadingValue Value="@_editorItems" IsFixed="true">
@FieldItems?.Invoke(Model)
</CascadingValue>
@if (FirstRender)
@if (_firstRender)
{
<div class="ef-loading">
<Spinner Color="Color.Primary" />
Expand Down
Loading