Skip to content

68ociredef/spring-filter-ng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 

Repository files navigation

Spring-filter-ng

A filter builder to manage Spring Filter library for Angular application.

NPM Version NPM Downloads NPM Downloads total

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","example@mail.it").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 .

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:

const filter = new SpringFilter()
    .build() 
    .orLike("firstName", SpringFilterUtils.likeRight(value))
    .orLike("lastName", SpringFilterUtils.likeRight(value))
    .andEquals("id", value).value
 

Date builder

It is possible to use a date builder to manage date input.

Configuration's parameter

Param default value
localeFe en
localeBe en
literalFe /
literalBe /

Example

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 ⭐.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published