Skip to content

Commit

Permalink
Suppport CRUD modal forms (gustavnavar/Grid.Blazor#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgentry09 committed May 4, 2023
1 parent 818e6f9 commit 5486e5d
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 14 deletions.
6 changes: 6 additions & 0 deletions GridBlazor/CGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ public PagingType PagingType

public bool ChangeVirtualizedHeight { get; set; } = false;

public bool ModalForms { get; set; } = false;

public string ModalWidth { get; set; }

public string ModalHeight { get; set; }

/// <summary>
/// Get and set export to an Excel file
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions GridBlazor/Client/GridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ public IGridClient<T> ChangeVirtualizedHeight(bool enable)
return this;
}

public IGridClient<T> SetModalForms(bool enable, string width = null, string height = null)
{
_source.ModalForms = enable;
_source.ModalWidth = width;
_source.ModalHeight = height;
return this;
}

public IGridClient<T> Sortable()
{
return Sortable(true, GridSortMode.ThreeState);
Expand Down
12 changes: 9 additions & 3 deletions GridBlazor/Client/IGridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,25 @@ public interface IGridClient<T>
/// <summary>
/// Enable virtualization
/// </summary>
IGridClient<T> Virtualize(int heigh);
IGridClient<T> Virtualize(int height);

/// <summary>
/// Enable virtualization
/// </summary>
IGridClient<T> Virtualize(string width, int heigh);
IGridClient<T> Virtualize(string width, int height);

/// <summary>
/// Enable change virtualized height for grid
/// </summary>
/// <param name="enable">Enable dynamic setup the virtualized heighte of the grid</param>
/// <param name="enable">Enable dynamic setup the virtualized height of the grid</param>
IGridClient<T> ChangeVirtualizedHeight(bool enable);

/// <summary>
/// Enable modal CRUD forms
/// </summary>
/// <param name="enable">Enable modal forms for the grid</param>
IGridClient<T> SetModalForms(bool enable, string width = null, string height = null);

/// <summary>
/// Enable sorting for all columns
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions GridBlazor/ICGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,20 @@ public interface ICGrid : IGrid, IGridOptions
/// Enable the change of the virtualized grid height
/// </summary>
bool ChangeVirtualizedHeight { get; set; }

/// <summary>
/// Enable modal CRUD forms
/// </summary>
bool ModalForms { get; set; }

/// <summary>
/// Get value for modal CRUD form width
/// </summary>
string ModalWidth { get; set; }

/// <summary>
/// Get value for modal CRUD form height
/// </summary>
string ModalHeight { get; set; }
}
}
2 changes: 1 addition & 1 deletion GridBlazor/Pages/BooleanFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", boolFilter);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", boolFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/DateTimeFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", firstSelect);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", dateTimeFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/DateTimeLocalFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", firstSelect);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", dateTimeFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/FormTooltipComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", tooltip);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", tooltip);
ScreenPosition gridComponentSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridComponent.Gridmvc);
ScreenPosition gridComponentSP = GridComponent.gridComponentSP;
if (GridComponent.Grid.Direction == GridShared.GridDirection.RTL)
{
if (sp != null && gridComponentSP != null && sp.X < Math.Max(35, gridComponentSP.X))
Expand Down
80 changes: 79 additions & 1 deletion GridBlazor/Pages/GridComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
<div @ref="Spinner" class="grid-spinner" style="display:none;"></div>
<div @ref="Content">
@if (Grid.Mode == GridMode.Grid)
@if (Grid.Mode == GridMode.Grid || Grid.PagingType == PagingType.Virtualization || Grid.ModalForms)
{
if (Grid.ComponentOptions.RenderRowsOnly)
{
Expand Down Expand Up @@ -458,6 +458,84 @@
</div>
</div>
</div>

@if (Grid.Mode != GridMode.Grid)
{
<div class="modal fade show ml-3" tabindex="-1" role="dialog" style="display:block;position:absolute;">
<div class="modal-dialog" role="document" style="position:absolute;">
<div class="modal-content grid-crud" style="overflow-y:scroll;@(!string.IsNullOrWhiteSpace(Grid.ModalWidth) ? "width:" + Grid.ModalWidth + ";" : (gridComponentSP == null ? "" : "width:" + gridComponentSP.Width + "px;")) @(!string.IsNullOrWhiteSpace(Grid.ModalHeight) ? "height:" + Grid.ModalHeight + ";" : (gridComponentSP == null ? "" : "height:" + (int)(gridComponentSP.Height * 0.96) + "px;"))">
<div class="modal-body">
@if (Grid.Mode == GridMode.Create && Grid.CreateEnabled)
{
<div dir="@Grid.Direction.ToDirection()">
@if (Grid.CreateComponent == null)
{
<CascadingValue Value=@this Name="GridComponent">
<GridCreateComponent @ref="CreateComponent" T="@T" Item="@Item"></GridCreateComponent>
</CascadingValue>
}
else
{
@CrudRender
}
</div>
}
else if (Grid.Mode == GridMode.Read && (Grid.ReadEnabled || (((CGrid<T>)Grid).FuncReadEnabled != null && ((CGrid<T>)Grid).FuncReadEnabled(Item))))
{
<div dir="@Grid.Direction.ToDirection()">
@if (Grid.ReadComponent == null)
{
<CascadingValue Value=@this Name="GridComponent">
<GridReadComponent @ref="ReadComponent" T="@T" Item="@Item"></GridReadComponent>
</CascadingValue>
}
else
{
@CrudRender
}
</div>
}
else if (Grid.Mode == GridMode.Update && (Grid.UpdateEnabled || (((CGrid<T>)Grid).FuncUpdateEnabled != null && ((CGrid<T>)Grid).FuncUpdateEnabled(Item))))
{
<div dir="@Grid.Direction.ToDirection()">
@if (Grid.UpdateComponent == null)
{
<CascadingValue Value=@this Name="GridComponent">
<GridUpdateComponent @ref="UpdateComponent" T="@T" Item="@Item"></GridUpdateComponent>
</CascadingValue>
}
else
{
@CrudRender
}
</div>
}
else if (Grid.Mode == GridMode.Delete && (Grid.DeleteEnabled || (((CGrid<T>)Grid).FuncDeleteEnabled != null && ((CGrid<T>)Grid).FuncDeleteEnabled(Item))))
{
<div dir="@Grid.Direction.ToDirection()">
@if (Grid.DeleteComponent == null)
{
<CascadingValue Value=@this Name="GridComponent">
<GridDeleteComponent @ref="DeleteComponent" T="@T" Item="@Item"></GridDeleteComponent>
</CascadingValue>
}
else
{
@CrudRender
}
</div>
}
else if (Grid.Mode == GridMode.Form)
{
<div dir="@Grid.Direction.ToDirection()">
@CrudRender
</div>
}
</div>
</div>
</div>
</div>
}
}
}
else if (Grid.Mode == GridMode.Create && Grid.CreateEnabled)
Expand Down
6 changes: 6 additions & 0 deletions GridBlazor/Pages/GridComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public partial class GridComponent<T>
internal ElementReference GridTable;
internal ElementReference GridTableWrap;

internal ScreenPosition gridComponentSP;
internal ScreenPosition gridTableSP;

internal ElementReference Spinner;
internal ElementReference Content;

Expand Down Expand Up @@ -330,6 +333,9 @@ protected override bool ShouldRender()

protected override async Task OnAfterRenderAsync(bool firstRender)
{
gridComponentSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", Gridmvc);
gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridTable);

if (firstRender)
{
IsDateTimeLocalSupported = await jSRuntime.InvokeAsync<bool>("gridJsFunctions.isDateTimeLocalSupported");
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/HeaderTooltipComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", tooltip);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", tooltip);
ScreenPosition gridComponentSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridComponent.Gridmvc);
ScreenPosition gridComponentSP = GridComponent.gridComponentSP;
if (GridComponent.Grid.Direction == GridShared.GridDirection.RTL)
{
if (sp != null && gridComponentSP != null && sp.X < Math.Max(35, gridComponentSP.X))
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/ListFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", listFilter);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", listFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/MonthFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", firstSelect);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", dateTimeFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/NumberFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", firstSelect);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", numberFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/TextFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", firstSelect);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", textFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/WeekFilterComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
await jSRuntime.InvokeVoidAsync("gridJsFunctions.focusElement", firstSelect);
ScreenPosition sp = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", dateTimeFilter);
ScreenPosition gridTableSP = await jSRuntime.InvokeAsync<ScreenPosition>("gridJsFunctions.getPosition", GridHeaderComponent.GridComponent.GridTable);
ScreenPosition gridTableSP = GridHeaderComponent.GridComponent.gridTableSP;
if (sp != null && gridTableSP != null)
{
if (gridTableSP.X + gridTableSP.Width < sp.X + sp.Width)
Expand Down

0 comments on commit 5486e5d

Please sign in to comment.