### Install CLI Template Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Install the Bootstrap Blazor CLI template globally using the .NET CLI. ```bash dotnet new install Bootstrap.Blazor.Templates::* ``` -------------------------------- ### Install Bootstrap Blazor Package Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Use the .NET CLI to add the BootstrapBlazor package to your project. ```bash dotnet add package BootstrapBlazor ``` -------------------------------- ### Create Project with CLI Template Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Generate a new Blazor project pre-configured with Bootstrap Blazor using the installed template. ```bash dotnet new bbapp ``` -------------------------------- ### Implement IDataService for Data Grid Operations Source: https://context7.com/dotnetcore/bootstrapblazor/llms.txt Implement the IDataService interface to provide CRUD operations for Blazor data grids like Table. This example shows a concrete implementation for managing Product data, including querying, saving, and deleting. ```csharp // MyProductDataService.cs public class MyProductDataService : DataServiceBase { private readonly AppDbContext _db; public MyProductDataService(AppDbContext db) => _db = db; public override async Task> QueryAsync(QueryPageOptions options) { var query = _db.Products.AsQueryable(); if (!string.IsNullOrEmpty(options.SearchText)) query = query.Where(p => p.Name.Contains(options.SearchText)); if (options.SortName == nameof(Product.Price)) query = options.SortOrder == SortOrder.Asc ? query.OrderBy(p => p.Price) : query.OrderByDescending(p => p.Price); var total = await query.CountAsync(); var items = await query .Skip((options.PageIndex - 1) * options.PageItems) .Take(options.PageItems) .ToListAsync(); return new QueryData { Items = items, TotalCount = total }; } public override async Task SaveAsync(Product model, ItemChangedType type) { if (type == ItemChangedType.Add) _db.Products.Add(model); else _db.Products.Update(model); return await _db.SaveChangesAsync() > 0; } public override async Task DeleteAsync(IEnumerable models) { _db.Products.RemoveRange(models); return await _db.SaveChangesAsync() > 0; } } ``` ```csharp // Program.cs registration builder.Services.AddScoped, MyProductDataService>(); ``` -------------------------------- ### Basic Component Usage Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Example of using the Display and Button components in a Blazor component. The Button's OnClick event updates a string displayed by the Display component. ```razor @code { private string? _text; private void ClickButton(MouseEventArgs e) { _text = DateTime.Now.ToString(); } } ``` -------------------------------- ### Configure MainLayout.razor Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Wrap your application's content with BootstrapBlazorRoot in MainLayout.razor to enable component functionality. ```html @Body ``` -------------------------------- ### Register Services in Program.cs Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Add the necessary Bootstrap Blazor services to your application's service collection in Program.cs. ```csharp builder.Services.AddBootstrapBlazor(); ``` -------------------------------- ### Add JavaScript Reference Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Add the Bootstrap Blazor JavaScript bundle at the end of the body in your main HTML file. ```html ``` -------------------------------- ### Layout Component with Header, Footer, and Sidebar Source: https://context7.com/dotnetcore/bootstrapblazor/llms.txt Implement an application shell using the Layout component. Configure sidebar menus, header, footer, and content area. Integrates with AuthorizeView for role-based menu rendering. ```razor
My Enterprise App
© 2024 My Company
@code { private List _menus = new() { new MenuItem { Text = "Dashboard", Url = "/dashboard", Icon = "fa-solid fa-gauge" }, new MenuItem { Text = "Products", Url = "/products", Icon = "fa-solid fa-box" }, new MenuItem { Text = "Orders", Url = "/orders", Icon = "fa-solid fa-list" }, }; private Task OnAuthorizing(string url) { // Return false to redirect to NotAuthorized content return Task.FromResult(true); } } ``` -------------------------------- ### Add CSS Reference Source: https://github.com/dotnetcore/bootstrapblazor/blob/main/src/BootstrapBlazor/readme.md Include the Bootstrap Blazor CSS bundle in the head section of your main HTML file (index.html or _Layout.cshtml/_Host.cshtml/App.razor). ```html ``` -------------------------------- ### PrintService Source: https://context7.com/dotnetcore/bootstrapblazor/llms.txt PrintService opens a dialog for print-preview purposes, reusing DialogService internally to render any content in a printable modal. ```APIDOC ## PrintService `PrintService` opens a dialog for print-preview purposes, reusing `DialogService` internally to render any content in a printable modal. ```razor @inject PrintService PrintService