darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
440 stars 174 forks source link

Filter by "<column> NOT IN (<input array>)" #138

Closed jacevedo-emc closed 2 years ago

jacevedo-emc commented 2 years ago

Hi,

I have a table with a integer column and I want to filter by " NOT IN ()". How could I do it?

Thanks

jacevedo-emc commented 2 years ago

Hi, I found how to do it:

Specification< MyEntityTable > notINSpecification = ( Specification< MyEntityTable > ) ( root, query, criteriaBuilder ) -> {
    return criteriaBuilder.not( criteriaBuilder.in( root.get( "id" ) ).value( listOfIDsToExclude ) );
};

return myEntityTableRepository.findAll( input, notINSpecification );

Best regards

darrachequesne commented 2 years ago

Exactly, you are right! :+1:

I think we can close this now.