A filter builder to manage Spring Filter library for Angular application.
npm install spring-filter-ng
npm install spring-filter-ng
`
Angular Support
Angular | Spring-filter-ng | Status |
----------| --------------- | ----------- |
18 | 7.x | Active |
17 | 6.x | - |
16 | 5.x | - |
15 | 4.x | - |
14 | 3.x | - |
12/13 | 1.x+ | - |
Usage
`ts
import {SpringFilter, SpringFilterUtils } from 'spring-filter-ng';
`
`ts
...
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)......
}
`
Example
`ts
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;
`
Utils
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
Compact expressions.
It is possible to use expressions more compact in this way:
`ts
const filter = new SpringFilter()
.build()
.orLike("firstName", SpringFilterUtils.likeRight(value))
.orLike("lastName", SpringFilterUtils.likeRight(value))
.andEquals("id", value).value
``