Janar.DataTable
1.1.6
dotnet add package Janar.DataTable --version 1.1.6
NuGet\Install-Package Janar.DataTable -Version 1.1.6
<PackageReference Include="Janar.DataTable" Version="1.1.6" />
<PackageVersion Include="Janar.DataTable" Version="1.1.6" />
<PackageReference Include="Janar.DataTable" />
paket add Janar.DataTable --version 1.1.6
#r "nuget: Janar.DataTable, 1.1.6"
#:package Janar.DataTable@1.1.6
#addin nuget:?package=Janar.DataTable&version=1.1.6
#tool nuget:?package=Janar.DataTable&version=1.1.6
๐ Janar.DataTable
A powerful, flexible, and modern data table component for Blazor Server and MAUI Blazor Hybrid apps.
Built to support dynamic columns, rich formatting, searching, pagination, and client-side export โ all styled with Bootstrap 5.
โ Support
If you find this package helpful, please consider supporting me:
โจ Features
- ๐ Dynamic Columns via reflection
- โ๏ธ Custom Column Configuration (name, order, visibility)
- โ๏ธ Sortable Headers
- ๐ Search Filtering
- ๐ Pagination
- ๐ค Export to CSV, Excel, and PDF (client-side)
- ๐จ Bootstrap 5 Styling
- ๐ ๏ธ Action Buttons Support (Edit/Delete)
- ๐งฉ Custom Column Templates via
RenderFragment
๐ Getting Started
โ Basic Usage
Use Janar.DataTable with auto-generated columns:
<DataTable TItem="Employee"
Items="@employees" />
โ๏ธ Advanced Usage
1. ๐ ๏ธ Column Configuration
Define custom column headers, visibility, order, and templates:
private List<ColumnConfiguration> columnConfigurations = new()
{
new() { PropertyName = "Id", HeaderName = "ID", Order = 1, Visible = true },
new() { PropertyName = "Name", HeaderName = "Full Name", Order = 2, Visible = true },
new() { PropertyName = "Position", HeaderName = "Position", Order = 3, Visible = true },
new() { PropertyName = "Office", HeaderName = "Office", Order = 4, Visible = true },
new() { PropertyName = "Salary", HeaderName = "Salary", Order = 5, Visible = true, Template = customEmployee },
new() { PropertyName = "JoiningDate", HeaderName = "Joining Date", Order = 6, Visible = true },
new() { PropertyName = "LoginTime", HeaderName = "Login Time", Order = 7, Visible = true, Template = lgnTime },
new() { PropertyName = "YearsAtCompany", HeaderName = "Years At Company", Order = 8, Visible = true }
};
<DataTable TItem="Employee"
Items="@employees"
ColumnConfigurations="@columnConfigurations" />
2. ๐ฏ Column Formatting
Format data (e.g., currency, dates, numbers) using ColumnFormats:
private Dictionary<string, string> columnFormats = new()
{
{ "Salary", "C2" }, // $62,000.00
{ "JoiningDate", "dd-MMM-yyyy" }, // 10-Apr-2018
{ "YearsAtCompany", "N0" } // 5
};
<DataTable TItem="Employee"
Items="@employees"
ColumnFormats="@columnFormats"
ColumnConfigurations="@columnConfigurations" />
3. ๐จ Custom Templates with RenderFragment
Use RenderFragment<T> for custom rendering:
private static RenderFragment<Employee> customEmployee => emp => builder =>
{
builder.OpenElement(0, "span");
builder.AddAttribute(1, "class", "btn btn-sm btn-primary me-2");
builder.AddContent(2, emp.Salary.ToString("C0"));
builder.CloseElement();
};
private static RenderFragment<Employee> lgnTime => emp => builder =>
{
builder.OpenElement(0, "span");
builder.AddAttribute(1, "class", "badge bg-info");
builder.AddContent(2, emp.Logintime.ToString("HH:mm:ss"));
builder.CloseElement();
};
<DataTable TItem="Employee"
Items="@employees"
ColumnConfigurations="@columnConfigurations" />
4. ๐งฐ Action Buttons (Edit/Delete)
Define handlers for editing and deleting rows:
private void EditItem(Employee employee)
{
// Handle edit logic here
}
private void DeleteItem(Employee employee)
{
// Handle delete logic here
}
<DataTable TItem="Employee"
Items="@employees"
OnEdit="EditItem"
OnDelete="DeleteItem" />
๐ฆ Export Functionality
When ExportButtons = true, the component shows export buttons for CSV, Excel, and PDF.
โ Required CSS
Include these in your layout file (e.g., _Host.cshtml, App.cshtml, index.html, or MauiBlazorHostPage.xaml):
<link href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined" rel="stylesheet">
<link href="_content/Janar.Datatable/assets/css/datatable.css" rel="stylesheet" />
โ ๏ธ Note
If _content/Janar.Datatable/assets/css/datatable.css doesn't apply styles correctly,
you can download datatable.css manually from:
โ Required Scripts
Place these before the closing </body> tag:
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="_content/Janar.Datatable/assets/js/datatable.js"></script>
<script src="_content/Janar.Datatable/assets/js/exporter.js"></script>
๐งฉ Component Parameters
| Parameter | Type | Description |
|---|---|---|
TItem |
Type |
Generic item type (e.g., Employee) |
Items |
IEnumerable<TItem> |
Data source for the table |
ColumnFormats |
Dictionary<string, string> |
Format strings per column |
ColumnConfigurations |
List<ColumnConfiguration> |
Header, visibility, order, templates |
OnEdit |
EventCallback<TItem> |
Row Edit button callback |
OnDelete |
EventCallback<TItem> |
Row Delete button callback |
ExportButtons |
bool |
Shows export buttons (CSV, Excel, PDF) |
ActionsButtons |
bool |
Shows Edit/Delete buttons |
Search |
bool |
Enables search input |
TableStyle |
string |
Bootstrap classes to style the table |
UndefinedColumns |
bool |
Auto-detect and display public props |
๐งช Full Integration Example
<DataTable5 TItem="Employee"
Items="@employees"
ColumnConfigurations="@clmnOrderConfigs"
OnEdit="EditEmployee"
OnDelete="DeleteEmployee"
ExportButtons="false"
Search="false"
TableStyle="table-dark table-striped table-bordered"
ActionsButtons="false"
UndefinedColumns="false" />
๐๏ธ Column Configuration Example
private List<ColumnConfigWithOrder<Employee>> clmnOrderConfigs = new()
{
new() { PropertyName = "DefinedName", Visible = true, Header = "Name", Align = "left", Order = 1 },
new() { PropertyName = "EmployeePosition", Visible = true, Header = "Position", Align = "center", Order = 2 },
new() { PropertyName = "EmployeeSalary", Visible = true, Header = "Salary ๐ฐ", Align = "right", Order = 3,
Template = employee => @<span class="text-success fw-bold">@employee.Salary.ToString("C0")</span> },
new() { PropertyName = "EmployeeYearsAtCompany", Visible = true, Header = "Years @ Co.โณ", Align = "center", Order = 4,
Template = employee => @<span class="badge bg-info">@employee.YearsAtCompany</span> }
};
Templateallows custom rendering usingRenderFragment<TItem>Aligncontrols text alignment (left,center,right)Orderdetermines column display orderVisibleshows or hides the column
โ๏ธ Behavior: UndefinedColumns
If
UndefinedColumns = true(default):- All public properties on
TItemare auto-detected and displayed - You can override properties via
ColumnConfigurations
- All public properties on
If
UndefinedColumns = false:- Only columns defined in
ColumnConfigurationswithVisible = trueare shown
- Only columns defined in
This gives you flexibility for both quick setup and fine-grained control.
๐จ Styling Tips
- Use the
TableStyleparameter to apply Bootstrap classes:
TableStyle="table table-dark table-striped table-bordered"
- To add rounded corners:
.table-wrapper {
border-radius: 5px;
overflow: hidden;
}
Wrap your <table> with a .table-wrapper div to enable rounded borders.
Customize sorting icons by overriding classes like:
.sort-indicator.sort-arrow.sort-active.sort-disabled
โ ๏ธ .NET 8 Interactive Notice
If you're
using Blazor Web Components in .NET 8, ensure the component is rendered with an interactive render mode like:
@rendermode="InteractiveServer"
Otherwise, features such as search, sort, and pagination will not function.
๐ Versioning & Changes
When updating versions, ensure the following are reflected:
โ Added Parameters:
ExportButtonsActionsButtonsSearchTableStyleUndefinedColumns
โ ๏ธ Changed Behavior:
- With
UndefinedColumns = true, all columns are auto-detected unless configured
- With
๐จ CSS & Styling Updates:
- Improved dark mode support
- Enhanced sorting styles
- Better Bootstrap 5 compatibility
๐ GitHub Demo
๐งพ License
MIT ยฉ [Janar Group]
๐ Acknowledgments
- Uses SheetJS for Excel exports
- Built with โค๏ธ by Janar Group using Blazor and Bootstrap 5
Thank you for using Janar.DataTable!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.20)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.