BlazorCommon 1.0.9
See the version list below for details.
dotnet add package BlazorCommon --version 1.0.9
NuGet\Install-Package BlazorCommon -Version 1.0.9
<PackageReference Include="BlazorCommon" Version="1.0.9" />
paket add BlazorCommon --version 1.0.9
#r "nuget: BlazorCommon, 1.0.9"
// Install BlazorCommon as a Cake Addin #addin nuget:?package=BlazorCommon&version=1.0.9 // Install BlazorCommon as a Cake Tool #tool nuget:?package=BlazorCommon&version=1.0.9
What is BlazorCommon?
It is a set of Blazor components grouped in an RCL library with the purpose of speeding up the construction of applications and contributing to both own and collective knowledge.
Dependencies
In current version
- net7.0 (For projects in .net 6 use Version 6.00)
- ClosedXML (>= 0.100.3)
- Microsoft.AspNetCore.Components .Web (>= 7.0.0)
How it works?
After installing the Nuget package we can start using the components in a Blazor project.
using BlazorCommon;
using BlazorCommon.Grid;
...
Grid
Grids are one of the most used components today, they are also one of the main headaches when it comes to maintaining the code. We present a simple and configurable option.
How to implement it
Code behind
using BlazorCommon.Grid;
using BlazorCommon;
using Microsoft.AspNetCore.Components;
namespace BlazorCommonTester.Pages
{
public class GridBase : HtmlComponentBase
{
protected GridConfigurationBase GridC { get; set; }
protected override async Task OnInitializedAsync()
{
GridC = await GridConfigurationBase.GetInstanceAsync();
await base.OnInitializedAsync();
}
}
}
Front
<BlazorCommon.Grid.Grid GridConfig="GridC" />
If your practical interest is not to always present the same information about the last time an animal was sighted, all you have to do is overwrite the GetList() method of the QueryResultBase Class.
QueryResultBase Class
public class QueryResultBase
{
public int NotFilteredTotal { get; set; }
public int Total { get; set; }
public IEnumerable<RowBase> List { get; set; }
public int PageSize { get; set; }
public int PageIndex { get; set; }
public SortChangedEvent Sort { get; set; }
public QueryResultBase()
{
PageSize = 10;
PageIndex = 1;
}
public virtual void GetList()
{
List = Animal.GetAll();
}
Note: The List property of the class derives from RowBase; Thus, for everything to go well, the class that makes up the list must derive from this class.
public IEnumerable<RowBase> List { get; set; } // Property of QueryResultBase
public class RowBase
{
public string RowBaseBackGroundColor { get; set; }
public string RowBaseFontColor { get; set; }
public string RowBaseId { get; set; }
public bool RowBaseSelected { get; set; }
public bool RowBasePreviousSelected { get; set; }
public bool RowBaseVisible { get; set; }
public List<ExpandedRowOption> ExpandedRowOptions { get; set; }
public bool RowExpanded { get; set; }
public RowBase()
{
RowBaseBackGroundColor = "white";
RowBaseFontColor = "black";
Random r = new Random();
int rInt = r.Next(0, 100000000);
RowBaseId = $"row_{rInt}";
RowBaseVisible= true;
}
public virtual void SetExpandedRowOptions()
{
ExpandedRowOptions = Enum.GetValues(typeof(ExpandedRowOption)).Cast<ExpandedRowOption>().ToList();
}
public virtual async Task OnRowClick(JsHelper jsHelper)
{
RowExpanded = !RowExpanded;
if(RowExpanded)
{
SetExpandedRowOptions();
await jsHelper.SetSessionStorage("row", this);
}
else
{
await jsHelper.RemoveSessionStorage("row");
}
}
}
The RowBase class determines the behavior and appearance of rows within the table, so the list received by the grid must inherit from it.
public class MyList: RowBase
{
...
}
Filters
By default the grid implements the filters and the ordering of all its columns. This can be changed using a class derived from GridColumnBase. This in turn is initialized from GridConfigurationBase, which is finally the object that we pass as a parameter to the component.
public virtual List<GridColumnBase> GetGridColumnBase()
{
List<PropertyInfo> baseProperties = new RowBase().GetType().GetProperties().ToList();
List<PropertyInfo> props = ItemType.GetProperties().Where(x => !baseProperties.Any(s => s.Name == x.Name)).ToList();
return props.Select(x => new GridColumnBase(x, props.IndexOf(x), KeyColumn)).ToList();
}
// And GridColumnBase constructor
public GridColumnBase(PropertyInfo prop, int position, string keyColumnName, bool searchable =true, bool sortable= true)
{
...
}
Summary
As you can see, it is enough to change the data source and that the objects in this list belong to a class derived from RowBase. There are many things that can be configured. We invite you to explore the complete code of the project in GitHub.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net7.0
- ClosedXML (>= 0.100.3)
- Microsoft.AspNetCore.Components.Web (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.3.5 | 136 | 2/23/2024 |
1.3.4 | 183 | 1/2/2024 |
1.3.1 | 190 | 5/30/2023 |
1.3.0 | 195 | 4/20/2023 |
1.2.9 | 188 | 4/16/2023 |
1.2.8 | 188 | 4/16/2023 |
1.2.7 | 189 | 4/16/2023 |
1.2.6 | 234 | 3/14/2023 |
1.2.5 | 216 | 3/13/2023 |
1.2.4 | 218 | 3/13/2023 |
1.2.3 | 235 | 3/13/2023 |
1.2.2 | 219 | 3/13/2023 |
1.2.1 | 254 | 3/10/2023 |
1.2.0 | 208 | 3/10/2023 |
1.1.9 | 239 | 3/7/2023 |
1.1.8 | 242 | 3/7/2023 |
1.1.7 | 205 | 3/7/2023 |
1.1.6 | 247 | 3/5/2023 |
1.1.5 | 230 | 3/4/2023 |
1.1.4 | 249 | 3/3/2023 |
1.1.3 | 241 | 3/2/2023 |
1.1.2 | 277 | 2/28/2023 |
1.1.1 | 229 | 2/28/2023 |
1.1.0 | 236 | 2/28/2023 |
1.0.9 | 256 | 2/27/2023 |
1.0.8 | 253 | 2/27/2023 |
1.0.5 | 247 | 2/25/2023 |
1.0.4 | 231 | 2/24/2023 |
1.0.3 | 263 | 2/19/2023 |
1.0.2 | 254 | 2/18/2023 |
1.0.1 | 243 | 2/17/2023 |
Adding Readme.