BlazorCommon 1.3.5

dotnet add package BlazorCommon --version 1.3.5
NuGet\Install-Package BlazorCommon -Version 1.3.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorCommon" Version="1.3.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorCommon --version 1.3.5
#r "nuget: BlazorCommon, 1.3.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlazorCommon as a Cake Addin
#addin nuget:?package=BlazorCommon&version=1.3.5

// Install BlazorCommon as a Cake Tool
#tool nuget:?package=BlazorCommon&version=1.3.5

Getting Started Getting Started

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.

Getting Simple grid

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 = new GridConfigurationBase();
           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.

Getting filter grid


  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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 125 2/23/2024
1.3.4 165 1/2/2024
1.3.1 175 5/30/2023
1.3.0 180 4/20/2023
1.2.9 174 4/16/2023
1.2.8 175 4/16/2023
1.2.7 173 4/16/2023
1.2.6 218 3/14/2023
1.2.5 204 3/13/2023
1.2.4 206 3/13/2023
1.2.3 221 3/13/2023
1.2.2 205 3/13/2023
1.2.1 239 3/10/2023
1.2.0 194 3/10/2023
1.1.9 226 3/7/2023
1.1.8 221 3/7/2023
1.1.7 191 3/7/2023
1.1.6 231 3/5/2023
1.1.5 216 3/4/2023
1.1.4 234 3/3/2023
1.1.3 229 3/2/2023
1.1.2 262 2/28/2023
1.1.1 214 2/28/2023
1.1.0 222 2/28/2023
1.0.9 239 2/27/2023
1.0.8 240 2/27/2023
1.0.5 230 2/25/2023
1.0.4 215 2/24/2023
1.0.3 249 2/19/2023
1.0.2 238 2/18/2023
1.0.1 229 2/17/2023

DetailCollapsable