Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SveNord/Sve-Blazor-DataTable
https://github.com/SveNord/Sve-Blazor-DataTable
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/SveNord/Sve-Blazor-DataTable
- Owner: SveNord
- License: mit
- Created: 2020-05-25T17:20:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-27T23:10:23.000Z (over 1 year ago)
- Last Synced: 2024-08-01T15:05:16.802Z (4 months ago)
- Language: HTML
- Size: 4.79 MB
- Stars: 46
- Watchers: 7
- Forks: 14
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Sve-Blazor-DataTable
Blazor DataTable component with support for client/server side paging, filtering and sorting, build on top of bootstrap 4.
![Main gif](/Sve-Blazor-DataTable-Examples/Content/Main.gif)
## Important Notice
This project is still under active development! Currently an alpha version is available on NuGet, but keep in mind that a later version might contain breaking changes. Make sure to always check the [Changelog](CHANGELOG.md) for more information.```
### Planned work:- [] Code cleanup
- [] Better documentation
- [] Test cases
- [] Performance tests
- [] Memory consumption tests
- [] CPU usage tests
```### Installation
1. Install the [NuGet](https://www.nuget.org/packages/Sve.Blazor.DataTable/) package:```
> dotnet add package Sve.Blazor.DataTable
OR
PM> Install-Package Sve.Blazor.DataTable
```
Use the `--version` option to specify a specific version to install.Or use the build in NuGet package manager of your favorite IDEA. Simply search for `Sve.Blazor.DataTable`, select a version and hit install.
2. Import the components:
Add the following using statement `@using Sve.Blazor.DataTable.Components` to one of the following:
- For global import add it to your `_Imports.razor` file
- For a scoped import add it to your desired Blazor component3. Reference js interop file:
Add `` to your _Host.cshtml or your index.html## Usage
### DataTable properties
Name
Type
Default
DescriptionItems
IList
List
The list of items to displayUsePaging
bool
false
Boolean indicating whether to use paging or notPageNr
int
1
The number of the current page (only applicable when property UsePaging is true)PageSize
int
10
The amount of items shown on a page (only applicable when property UsePaging is true)PageCount
int
1
The total amount of pages (only applicable when property UsePaging is true)FetchData
Func<RequestArgs, Task>?
null
The method used for fetching and manipulating data (paging, filtering, sorting) on the server. When this method is null, all these actions will be performed on the initial dataset on the client.ShowHeaderFilters
bool
true
Indicates whether or not to show the header/grid filtersAllowRowSelection
bool
false
Indicates whether or not it's possible to select a rowRowClickedEvent
EventCallback
null
The callback for when a row is clicked (only applicable when property AllowRowSelection is true)SelectedItem
TModel
null
The selected itemSelectedItemCssClass
string
bg-info
The css class for the selected rowEmptyGridText
string
"No records to show"
The text to show when the Items list is emptyIsLoading
bool
false
Indicates whether or not data is being fetched, used to show a spinnerId
string
""
The html identifier of the table tagContainerCssClass
string
"table-responsive"
The css class for the container/parent tag of the tableCssClass
string
"table"
The css class for the table tagApplyButtonCssClass
string
""
The css class for the "apply" buttons on grid/header filtersInputCssClass
string
""
The css class for the input tags in the grid/header filtersStyles
TableStyle [Enum FLAGS]
null
The style flags used for the tableTableAttributes
Dictionary<string, object>?
null
Any custom attributes for the table tag (see Blazor docs for more info)RowAttributes
Dictionary<string, object>?
null
Any custom attributes for the rows (see Blazor docs for more info)ContainerHeight
int
300
The height of the table container in pixelsContainerHeightUnit
CssUnit
CssUnit.Px
The unit of the container heightIncludeAdvancedFilters
bool
true
Indicates whether to allow advanced filtering or notIncludeHeaderFilters
bool
false
Indicates whether or not to include grid/header filtersIncludeSearchButton
bool
false
Indicates whether or not to include a search icon. When clicked filters, sorting and paging is performed on the server is FetchData has a value otherwise it happens on the clientIncludeToggleFilters
bool
false
Indicates whether or not to include a toggle icon. When clicked header/grid filters will re or disappear (only applicable when propertySearchOnApplyHeaderFilter
bool
true
Indicates whether or not a search is instantly triggered when a header/grid filter is appliedAutoAddFilterWhenClickedAndNoneActive
bool
true
Indicates whether or not to add an empty filter rule when a filterable column is clicked an no other filter rules exist.ItemHeight
int?
null
The pixel height of a an item (tr) in the grid. Customize this to get better virtualization.### DataTableColumn properties
Name
Type
Default
DescriptionProperty
Expression<Func<TModel, object>>?
null
The selector of a field/property of TModel to use for the columnIsSortable
bool
false
Indicates whether or not sorting is enabled for this columnIsFilterable
bool
false
Indicates whether or not filtering is enabled for this columnIsResizable
bool
false
Indicates whether the column is resizable
IsVisible
bool
true
Indicates whether the column should be renderedCustomTitle
string
null
The name of the column header (by default the name of the property is used)HeaderTemplate
RenderFragment<string>
null
The template to use for the grid header, the string is the name of the columnId
string
""
The html identifier of the table tagContainerCssClass
string
"table-responsive"
The css class for the container/parent tag of the tableCssClass
string
"table"
The css class for the table tagIsDefaultSortColumn
bool
false
Indicates whether or not this column is sorted on by defaultDefaultSortDirection
SortDirection [Enum]
SortDirection.Ascending
The sort direction of the default sorting columnTextAlignment
TextAlignment [Enum]
TextAlignment.Left
The text alignment for the columnVerticalAlignment
VerticalAlignment [Enum]
VerticalAlignment.Bottom
The vertical alignment for the columnStyles
TableStyle [Enum FLAGS]
null
The style flags used for the tableAttributes
Dictionary<string, object>?
null
Any custom attributes for the table tag (see Blazor docs for more info)HeaderFilterAttributes
Dictionary<string, object>?
null
Any custom attributes for the header inputsContainerHeight
int
300
The height of the table container in pixelsMinWidthHeader
int
10
The height of the table container in the set units (default vw)MinWidthHeaderUnit
CssUnit
CssUnit.Vw
The unit of the minWidthHeader propertyIncludeHeaderFilter
bool
false
Indicates whether or not to add header/grid filtersIncludeSearchButton
bool
false
Indicates whether or not to include a search icon. When clicked filters, sorting and paging is performed on the server is FetchData has a value otherwise it happens on the clientIncludeToggleFilters
bool
false
Indicates whether or not to include a toggle icon. When clicked header/grid filters will re or disappear (only applicable when propertySearchOnApplyHeaderFilter
bool
false
Indicates whether or not a search is instantly triggered when a header/grid filter is appliedAutoAddFilterWhenClickedAndNoneActive
bool
true
Indicates whether or not to add an empty filter rule when a filterable column is clicked an no other filter rules exist.RowTemplate
RenderFragment?
null
The custom render fragment to use for the columnRowAttributes
Dictionary<string, object>?
null
Any custom attributes for the rows (see Blazor docs for more info)ContainerHeight
int
300
The height of the table container in pixelsMaxWidth
int
100
The max width in pixels of a columnMaxWidthUnit
CssUnit
CssUnit.Px
The unit of the MaxWidth propertyDateTimeFormat
DateTimeFormat
DateTimeFormat.Date
The DateTimeFormat to use in header/grid filtersIsHeaderVisible
bool
true
Indicates whether the column is visible or notIncludeAdvancedFilters
bool
false
Indicates whether to allow advanced filtering or notIncludeSearchButton
bool
false
Indicates whether or not to include a search icon. When clicked filters, sorting and paging is performed on the server is FetchData has a value otherwise it happens on the clientIncludeToggleFilters
bool
false
Indicates whether or not to include a toggle icon. When clicked header/grid filters will re or disappear (only applicable when propertySearchOnApplyHeaderFilter
bool
false
Indicates whether or not a search is instantly triggered when a header/grid filter is appliedAutoAddFilterWhenClickedAndNoneActive
bool
true
Indicates whether or not to add an empty filter rule when a filterable column is clicked an no other filter rules exist.### Basic table
```cs
```
![Basic example](/Sve-Blazor-DataTable-Examples/Content/BasicExample.PNG)
### Custom template
```cs
@if (forecast.UpdatedRecently)
{
}
else
{
}
```
![Template example](Sve-Blazor-DataTable-Examples/Content/CustomTemplateExample.PNG)
### Sorting
```cs
```
![Sorting example](/Sve-Blazor-DataTable-Examples/Content/SortingExample.gif)
### Pagination
```cs
```
![Paging example](/Sve-Blazor-DataTable-Examples/Content/PagingExample.gif)
### Filtering
```cs
```![Filtering example](/Sve-Blazor-DataTable-Examples/Content/FilteringExample.gif)
### Header/Grid filters
```cs
```![Header filtering example](/Sve-Blazor-DataTable-Examples/Content/HeaderFilteringExample.gif)
### Out of the box Virtualization
```cs
@(Array.IndexOf(forecasts, forecast) + 1)
```![Virtualization example](/Sve-Blazor-DataTable-Examples/Content/VirtualizationExample.gif)
### Server side support
```cs
// Method will be called by the DataTable when necessary
private async Task DoFetchData(RequestArgs args)
{
pagedForecasts = await ForecastService.SearchForecastAsync(args);
// Don't forget to call StateHasChanged() since your component is the owner of the DataTable
StateHasChanged();
}// ForecastService:
public async Task SearchForecastAsync(RequestArgs args)
{
IQueryable result = context.Forecasts.AsQueryable();// RequestArgs contains all the information about sorting, paging and filtering
foreach (var filter in args.AppliedFilters)
{
// Filters can easily be translated into expressions,
// or use the filtering info to create your own filtering solution
result = result.Where(filter.GenerateExpression());
}
// Use the Core.Utils to easily apply paging and sorting
// Or use the paging info in RequestArgs to build your own paging solution
pagedResult = Sve.Blazor.Core.Utils.ApplyPaging(result, pager);return Task.FromResult(pagedResult);
}
```![Server side example](/Sve-Blazor-DataTable-Examples/Content/ServerSideExample.gif)
### Support bootstrap table styles
```cs
....
```
![Small table example](/Sve-Blazor-DataTable-Examples/Content/SmallTableExample.PNG)
```cs
....
```
![Bordered table example](/Sve-Blazor-DataTable-Examples/Content/BorderedTableExample.PNG)
```cs
....
```
![Borderless table example](/Sve-Blazor-DataTable-Examples/Content/BorderlessTableExample.PNG)
```cs
....
```
![Dark table example](/Sve-Blazor-DataTable-Examples/Content/DarkTableExample.PNG)
```cs
....
```
![Hoverable table example](/Sve-Blazor-DataTable-Examples/Content/HoverableTableExample.PNG)
```cs
....
```
![Striped table example](/Sve-Blazor-DataTable-Examples/Content/StripedTableExample.PNG)
### Alignment
```cs
```
![Alignment example](/Sve-Blazor-DataTable-Examples/Content/AlignmentExample.PNG)
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details