@using AyCode.Blazor.Components.Components.Grids
@if (!OnlyGridEditTools)
{
@ToolbarItemsExtended
}
@code {
[Parameter] public bool OnlyGridEditTools { get; set; } = false;
[Parameter] public IMgGridBase Grid { get; set; } = null!;
[Parameter] public RenderFragment? ToolbarItemsExtended { get; set; }
[Parameter] public EventCallback OnReloadDataClick { get; set; }
[Parameter] public bool ShowOnlyIcon { get; set; } = false;
[Parameter] public bool EnableDelete { get; set; } = false;
public MgGridToolbarBase GridToolbar { get; set; } = null!;
const string ExportFileName = "ExportResult";
private bool _hasUserLayout;
private bool _isReloadInProgress;
///
/// Whether the grid is currently in edit mode (New or Edit)
///
private bool IsEditing => Grid?.GridEditState != MgGridEditState.None;
///
/// Whether the grid is currently syncing data
///
private bool IsSyncing => Grid?.IsSyncing ?? false;
///
/// Whether there is a focused row in the grid
///
private bool HasFocusedRow => Grid?.GetFocusedRowIndex() >= 0;
///
/// Whether the grid is currently in fullscreen mode
///
private bool IsFullscreenMode => Grid?.IsFullscreen ?? false;
///
/// Button text for fullscreen toggle
///
private string FullscreenButtonText => IsFullscreenMode ? "Exit Fullscreen" : "Fullscreen";
///
/// Icon class for fullscreen toggle button
///
private string FullscreenIconCssClass => IsFullscreenMode ? "grid-fullscreen-exit" : "grid-fullscreen";
protected override async Task OnInitializedAsync()
{
_hasUserLayout = await Grid.HasUserLayoutAsync();
}
async Task ReloadData_Click(ToolbarItemClickEventArgs e)
{
_isReloadInProgress = true;
try
{
await OnReloadDataClick.InvokeAsync(e);
}
finally
{
_isReloadInProgress = false;
}
}
async Task NewItem_Click()
{
await Grid.StartEditNewRowAsync();
}
async Task EditItem_Click()
{
await Grid.StartEditRowAsync(Grid.GetFocusedRowIndex());
}
void DeleteItem_Click()
{
Grid.ShowRowDeleteConfirmation(Grid.GetFocusedRowIndex());
}
async Task SaveItem_Click()
{
await Grid.SaveChangesAsync();
}
async Task CancelEdit_Click()
{
await Grid.CancelEditAsync();
}
void PrevRow_Click()
{
Grid.StepPrevRow();
}
void NextRow_Click()
{
Grid.StepNextRow();
}
void ColumnChooserItem_Click(ToolbarItemClickEventArgs e)
{
Grid.ShowColumnChooser();
}
void Fullscreen_Click()
{
Grid.ToggleFullscreen();
}
async Task ExportXlsxItem_Click()
{
await Grid.ExportToXlsxAsync(ExportFileName);
}
async Task ExportXlsItem_Click()
{
await Grid.ExportToXlsAsync(ExportFileName);
}
async Task ExportCsvItem_Click()
{
await Grid.ExportToCsvAsync(ExportFileName);
}
async Task ExportPdfItem_Click()
{
await Grid.ExportToPdfAsync(ExportFileName);
}
async Task LoadLayout_Click()
{
await Grid.LoadUserLayoutAsync();
}
async Task SaveLayout_Click()
{
await Grid.SaveUserLayoutAsync();
_hasUserLayout = true;
}
async Task ResetLayout_Click()
{
await Grid.ResetLayoutAsync();
}
}