G
Ginobel Del Carmen

MudBlazor DataGrid Region Market

MudBlazor Regions Manager lists regions with expandable child rows for markets and provides add/edit dialogs. Uses MudDataGrid with MudForm validation and Snackbar notifications.

LIVE DEMO
Generated using Instruct UI - An AI for Blazor UI Generation
## What's implemented - Region list using a MudDataGrid with hierarchical/child rows that expand to show markets. - Simple search field and client-side filter for region name. - Add/Edit dialog implemented with MudDialog and a MudForm that validates the region name. - Row actions for Edit and Remove; Remove uses a browser confirm via IJSRuntime and shows Snackbar notifications. ## Key components - MudDataGrid<T>, HierarchyColumn, PropertyColumn, TemplateColumn - MudTable<T> for child rows - MudDialog, MudForm, MudTextField, MudButton - IDialogService, ISnackbar, IJSRuntime - DTO models: RegionDto, MarketDto, SearchResultDto<T> ## How it works - Data is stored in-memory in a SearchResultDto<RegionDto> and _displayRegions is bound to the grid's Items. - The search box uses @bind-Value and ApplyFilter filters _searchResult.Items via LINQ (String.Contains, OrdinalIgnoreCase). - AddRegion and EditRegion open a MudDialog via DialogService.Show<T> and await dialog.Result; on success the returned RegionDto is merged into the in-memory list and StateHasChanged is called. - The Add/Edit dialog uses a MudForm reference and calls await _form.Validate() before closing with DialogResult.Ok(Region). - RemoveRegion calls JS.InvokeAsync<bool>("confirm", ...) to confirm deletion then removes the item and shows a Snackbar. ## Styling - Uses MudBlazor components and layout primitives (MudPaper, MudStack, MudSpacer) rather than utility CSS frameworks. - Component props control density, hover, elevation and spacing; responsive behavior follows MudBlazor layout patterns (stack/spacing) but no explicit media queries are present. ## Reuse steps 1. Add the MudBlazor NuGet package and static assets (MudBlazor CSS) to the project. 2. Register MudBlazor services in Program.cs (AddMudServices/AddMudTheme, DialogService, Snackbar) and add required using directives. 3. Copy DTOs (RegionDto, MarketDto, SearchResultDto<T>) and the two Razor components into the project. 4. Ensure IDialogService and ISnackbar are injected where used and IJSRuntime is available for confirm dialogs. 5. Replace the in-memory data with an injected data service or API client and implement paging/sorting if needed. ## Limitations & next steps - Sample uses in-memory data only; backend API, persistence, and service wiring are required for production. - Filtering is basic client-side string matching; no paging, server-side filtering, or sorting is implemented (SortMode.None). - Validation is limited to a required region name in the dialog; add DataAnnotations or custom validators for richer rules. - Consider adding optimistic updates, error handling, unit tests, and authentication/authorization for delete/edit actions.