HBH.FiltraCore is a .NET Core library for filtering collections of data. It provides a flexible and easy-to-use API for filtering data in a variety of ways.
Explore the docs »
View Demo
.
Report Bug
.
Request Feature
- About the Project
- Built With
- Getting Started
- Installation
- Usage
- Roadmap
- Contributing
- License
- Authors
The HBH.FiltraCore library is a .NET extension method library that allows you to apply advanced filters on a LINQ query. The main function in the library is ApplyAdvanceFilters
, which takes an IQueryable and an input object as input and returns the filtered query. The input object must have properties for Term, TermBy, and Filters. The Term and TermBy fields are used to filter the query based on a search term, and the Filters field is a JSON string that represents a list of filters to be applied on the query. The library supports various types of filters, such as equality, inequality, starts with, ends with, contains, and many others.
- Newtonsoft.Json for deserializing filters from a string
- System.Linq for building LINQ expressions
- System.Linq.Dynamic.Core for dynamically building LINQ expressions
To install HBH.FiltraCore, you can use the NuGet Package Manager in Visual Studio or the dotnet CLI.
NuGet Package Manager
PM> Install-Package HBH.FiltraCore
.NET CLI
dotnet add package HBH.FiltraCore
namespace Test
{
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Jobtitle { get; set; }
public decimal Salary { get; set; }
}
}
using HBH.FiltraCore;
namespace Test
{
public class AdvanceFilterRequestDto : IFiltraCoreRequestInput
{
public string Filters { get; set; }
public string Term { get; set; }
public string TermBy { get; set; }
}
}
namespace Test
{
public class EmployeeFilterRequestDto : AdvanceFilterRequestDto
{
// add your custom filters here
}
}
using HBH.FiltraCore;
namespace Test
{
[Authorize]
[ApiController]
[Route("app/service/[controller]")]
public class EmployeeController : ControllerBase
{
private readonly TestDbContext _testDbContext;
public EmployeeController(TestDbContext testDbContext)
{
_testDbContext = testDbContext;
}
}
public async Task<List<Employee>> SearchAsync(EmployeeFilterRequestDto input)
{
return await _testDbContext.Employees
// using ApplyAdvanceFilters extension
.ApplyAdvanceFilters(input)
.ToListAsync();
}
}
Term
is the value that you want to search forTermBy
is a comma separated string contains the fields that you want the term filter to by applied on
for example if you want to search using Term
on two fields Name
, Jobtitle
the request must be as bellow:
await fetch(`https://localhost:5000/app/service/employee?term=haitham&termBy=name,jobtitle`)
Filters
is a string contains a 2d array contains all your filters
[ ['ColumnName', 'FilterType', 'Value'] ]
- Contains:
"$contains"
- Not Contains:
"$notContains"
- Equal:
"$eq"
- Not Equal:
"$ne"
- Start With:
"$startsWith"
- EndsWith:
"$endsWith"
- Less Than:
"$lt"
- Less Than Or Equal:
"$lte"
- Greater Than:
"$gt"
- Greater Than Or Equal:
"$gte"
- Is Null:
"$null"
- Is Not Null:
"$notNull"
await fetch(`https://localhost:5000/app/service/employee?filters=[["salary","$eq","1000"],["jobtitle","$contains","developer"]]`)
See the open issues for a list of proposed features (and known issues).
Contributions to HBH.FiltraCore are always welcome!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
HBH.FiltraCore is licensed under the MIT License. This means that you are free to use the library for any purpose, including commercial use, and you can modify the source code as needed. However, please be sure to read the terms of the license carefully before using the library.
- Haitham Basim - Software developer - Haitham Basim - built the library