spring-filter-ng
v3.4.1
Published
A filter builder to manage Spring Filter library for Angular application.
Downloads
240
Maintainers
Readme
Spring-filter-ng
A filter builder to manage Spring Filter library for Angular application.
Getting started
Install Spring filter ng
npm install spring-filter-ng
Angular Support
Angular | Spring-filter-ng | Status | ----------| --------------- | ----------- | 14 | 3.x | Active | 12/13 | 1.x+ | - |
Usage
import {SpringFilter, SpringFilterUtils } from 'spring-filter-ng';
...
public searchByFilter() {
//initialize filter
const filterBuild = new SpringFilter().build();
//Build query
const filter = filterBuild.equals("email","[email protected]").value;
//Set parametrs for angular http.
const options = SpringFilterUtils.setOptions(value);
//Fetch datas.
this.fetchApiService.getStuffsByFilter(options)......
}
Example
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 .
Compact expressions.
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
Love spring-filter-ng ? Give to repo a star :star:.