This project is a rewrite of my other archived project SpringBootGenericPagingFilteringForPrimengTable to make it simple and easy to install
Spring Boot filter to convert PrimeNg table json request to JPA specification (paging, sorting and filtering for PrimeNg tables)
PrimeNg tables have a 'lazy' mode when displaying data, it sends all the requests of paging, sorting and filtering to the server to be processed. The goal of the this project is to make this server side processing the most generic possible (Spring boot).
<dependency>
<groupId>io.github.nabildridi</groupId>
<artifactId>PrimengTableSpringFilter</artifactId>
<version>1.3</version>
</dependency> loadUsersFromServer(event: TableLazyLoadEvent) {
event.globalFilter = ['username', 'lastname'];
this.http.post('http://dev.local/paginateUsers', event).subscribe({
next: (json: any) => {
if (json) {
this.data.set(json['content']);
this.totalRecords = json['totalElements'];
}
},
error: (e) => {
console.log('error');
},
});
}Example :
@Repository
public interface UsersRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> { import org.nd.primeng.model.User;
import org.nd.primeng.repositories.UsersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.turkraft.springfilter.boot.Filter;
import com.turkraft.springfilter.boot.Pagination;
@RestController
public class UsersController {
@Autowired
private UsersRepository usersRepository;
@PostMapping(value = "/paginateUsers")
public Page<User> paginate(@Filter Specification<User> spec, @Pagination Pageable page) {
return usersRepository.findAll(spec, page);
}
}The Specification and Pageable objects are automatically generated by Turkraft SpringFilter from the data provided by this project after parsing the Primeng json request.
The only thing that you need to do is to call findAll function of your target respository.
All the functions of Primeng table are supported :
- Pagination
- Sorting (single sort and multiple sort)
- All types of column filters (multiSelect, number, string, date, boolean and decimal)
- 'filterGlobal' input mode
See step 3, if you want to use the global filter, you need to specify what columns in your JPA entity to look into, for example, if you specify :
event.globalFilter = ['username', 'lastname'];Then when the user types 'Fred' in the global filter input, Spring will looks for values containing 'Fred' in username and lastname columns.
Caution
Don't add this annotation to your spring boot application
@EnableSpringDataWebSupport(pageSerializationMode = PageSerializationMode.VIA_DTO)That annotation generates a problem in the sort parameter of Turkraft SpringFilter
No, it doesn't work because its main dependency doesn't support Spring boot 4.x, as soon as the situation changes then I will update the project.
Java 17
- Spring boot version 3.5.10
- Angular version 21.1.0
- Primeng version 21.0.4