Get up and running
KBlazor is published on NuGet.org and runs in both Blazor Server and Blazor WebAssembly. Follow the steps below to add it to your project.
Install the package
Add KBlazor from the public NuGet.org feed using your preferred tool. No custom package source is required.
dotnet add package KBlazorInstall-Package KBlazor<PackageReference Include="KBlazor" Version="1.1.0" />Register services in Program.cs
KBlazor needs three scoped services and MudBlazor's service collection. Two more (IClientTimeZoneProvider, ITextMeasurer) are optional with built-in defaults.
using KBlazor.Services; using MudBlazor.Services; // MudBlazor (required by KBlazor components) builder.Services.AddMudServices(); // KBlazor — provide your own implementations or use the in-memory stubs builder.Services.AddScoped<IFlexTableSettings, YourFlexTableSettings>(); builder.Services.AddScoped<IListViewSettingStore, YourListViewSettingStore>(); builder.Services.AddScoped<IEntityLookupProvider, YourEntityLookupProvider>(); // Optional — show DateTimes in the browser's local time (Server or WebAssembly) builder.Services.AddScoped<IClientTimeZoneProvider, BrowserTimeZoneProvider>();
[AutoComplete] fields.Include kblazor.js
FlexTable uses a small script for column resizing, font detection, and auto-size. Add it to your host page.
<script src="_content/KBlazor/kblazor.js"></script><script src="_framework/blazor.webassembly.js"></script> <script src="_content/MudBlazor/MudBlazor.min.js"></script> <script src="_content/KBlazor/kblazor.js"></script>
Add namespaces to _Imports.razor
Add these usings so every component in your project can reference KBlazor types without qualification.
@using KBlazor.Components @using KBlazor.Models @using KBlazor.Services @using MudBlazor
Decorate your model with attributes
KBlazor reads [Display] attributes to build columns and form fields automatically. Additional attributes control editing behaviour, sorting, and rendering. Models implement IKBusinessEntity.
public class Order : IKBusinessEntity { [Key] public Guid Id { get; set; } [Display(Name = "Order #", Order = 1)] [ReadOnlyOnEdit] public string Name { get; set; } [ForeignKey("Customer")] public Guid? CustomerId { get; set; } // Entity column — filters by CustomerId, sorts by Customer.Name, // edits with an autocomplete backed by IEntityLookupProvider [Display(Name = "Customer", Order = 2)] [AutoComplete] [SortAndFilterOn(FilterPath = "CustomerId", SortPath = "Customer.Name")] public virtual Customer? Customer { get; set; } [Display(Name = "Amount", Order = 3)] public decimal Amount { get; set; } [Display(Name = "Notes", Order = 4)] [MemoDisplay] public string Notes { get; set; } }
Fields parameter on FlexTable and BasicEdit matches against
[Display(Name = "...")] values. See the
Attributes reference
for the full list of available attributes.
You're ready
Drop a component into any page and start building. Route the SortFilter callback through ApplyFilter / ApplySort so entity columns filter and sort correctly.
<FlexTable TItem="Order" Items="@_orders" Fields="Order #,Customer,Amount,Notes" SortFilter="OnSortFilter" /> @code { private IQueryable<Order> _orders = db.Orders.AsQueryable(); private void OnSortFilter(ListViewSetting setting) { _orders = db.Orders.AsQueryable().ApplyFilter(setting).ApplySort(setting); StateHasChanged(); } }