darrachequesne / spring-data-jpa-datatables

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

Order can be null #156

Closed smsotirov closed 8 months ago

smsotirov commented 8 months ago

On the latest datatables implementation, when you click on the order headers, there is 3 options. Ascending, descending and none. The spring-data-jpa-datatables plugin works on the first two, but fails on 3rd becasue of the validation in DataTablesInput for the field "order" which is @NotEmpty

To reproduse, just click more than twice on the order header on any column. You will see that the arrows toggles to ASC, DESC and the third option is basically none. I this third case, the request looks like this:

draw: 3
columns[0].data: name
columns[0].name: 
columns[0].searchable: true
columns[0].orderable: true
columns[0].search.value: 
columns[0].search.regex: false
columns[1].data: roleprefix
columns[1].name: 
columns[1].searchable: true
columns[1].orderable: true
columns[1].search.value: 
columns[1].search.regex: false
start: 0
length: 10
search.value: 
search.regex: false

No "order" in the request. This causes an error.

smsotirov commented 8 months ago

I forgot to add what is in the console:

[Field error in object 'dataTablesInput' on field 'order': rejected value [[]]; codes 
[NotEmpty.dataTablesInput.order,NotEmpty.order,NotEmpty.java.util.List,NotEmpty];
darrachequesne commented 8 months ago

Hi! I could indeed reproduce the issue with DataTables v2.0.1.

Columns can now have three ordering states - asc, desc or data index order (specified by an empty string). The columns.orderSequence option has been updated to make use of this, so the third ordering on a column will now take it back to the index order, rather than returning to the first direction.

Reference: https://cdn.datatables.net/2.0.0/

I think removing the @NotEmpty constraint should be enough, what do you think?

smsotirov commented 8 months ago

By the first glance over the code, I also think it will be enough. I think the addOrder() method will handle it.

darrachequesne commented 8 months ago

This should be fixed by https://github.com/darrachequesne/spring-data-jpa-datatables/commit/a214d5bb199fff4ccd578c3bbb71ee64f3a0f198, included in 6.0.2.