A filter builder to manage Spring Filter library for Angular application.
Install Spring filter ng
npm install spring-filter-ng
Angular | Spring-filter-ng | Status |
---|---|---|
14 | 3.x | Active |
12/13 | 1.x+ | - |
import {SpringFilter, SpringFilterUtils } from 'spring-filter-ng';
...
public searchByFilter() {
//initialize filter
const filterBuild = new SpringFilter().build();
//Build query
const filter = filterBuild.equals("email","example@mail.it").value;
//Set parametrs for angular http.
const options = SpringFilterUtils.setOptions(value);
//Fetch datas.
this.fetchApiService.getStuffsByFilter(options)......
}
Considering an employee
interface Employee {
id: number;
firstName: string;
lastName: string;
birthDate: string;
maritalStatus: string;
salary: number;
manager: Employee;
staff: Employee[];
}
1. If you want to know the employees who receive a salary greater than 3000:
const filter = SpringFilter.new().greaterThen("employee.salary", 3000).value;
2. If you want to know the employees who have marital status divorced or separated and have
at least two stuff members or are not manager:
const filter = SpringFilter.new().append("maritalStatus").in("divorced", "separated")
.and(SpringFilter.new().greaterThan(springFilter.instance().size("staff"), 2).or("manager").isNotNull()).value;
It is possbile to use utils method from SpringFilterUtils .
Name | Description |
---|---|
likeAll(parameter) | Search for values that have the parameter in input in any position |
likeLeft(parameter) | Search any values that start with the parameter in input. |
likeRight(parameter) | Search any values that end with the parameter in input. |
addAND(filter, parameter) | Conditional append and condition |
addOR(filter, parameter) | Conditional append or condition |
addNOT(filter, parameter) | Conditional append not condition |
isANumber(value) | Check the value in input is a number |
isAString(value) | Check the value in input is a string |
isADate(value) | Check the value in input is a date |
It is possible to use expressions more compact in this way:
const filter = new SpringFilter()
.build()
.orLike("firstName", SpringFilterUtils.likeRight(value))
.orLike("lastName", SpringFilterUtils.likeRight(value))
.andEquals("id", value).value
It is possible to use a date builder to manage date input.
Param | default value |
---|---|
localeFe | en |
localeBe | en |
literalFe | / |
literalBe | / |
Format the date in local date time adding a day, in italian format.
import {SfDateBuilder} from 'spring-filter-ng';
const data = new SfDateBuilder()
.configure({localeFe:'it'})
.build()
.localDateTime(value)
.dayAfter()
.value()
Love spring-filter-ng ? Give to repo a star ⭐.