vaadin / starters

Issue repository for all the starter projects in https://vaadin.com/start
3 stars 0 forks source link

[Grid] sorting not working with grid lazy loading created from designer #67

Closed letrthang closed 1 year ago

letrthang commented 2 years ago

Description of the bug

Just take example from starter. Sorting is not working using designer implementation.

image

code: https://github.com/letrthang/vaadin23-flow-pro-components/blob/main/src/main/java/com/example/application/views/masterdetaildesigner/MasterDetailDesignerView.java

https://github.com/letrthang/vaadin23-flow-pro-components/blob/main/frontend/views/masterdetaildesigner/master-detail-designer-view.ts

image

Note: pure java still works: https://github.com/letrthang/vaadin23-flow-pro-components/blob/main/src/main/java/com/example/application/views/masterdetailjava/MasterDetailJavaView.java

Expected behavior

can sort

Minimal reproducible example

https://github.com/letrthang/vaadin23-flow-pro-components

Versions

mcollovati commented 2 years ago

On the MasterDetailDesignerView columns are specified with addColumn(ValueProvider), so you have to configure them as sortable explicitly

grid.addColumn(SamplePerson::getFirstName).setHeader("First Name").setAutoWidth(true).setSortProperty("firstName");

On MasterDetailJavaView instead the columns are defined by the name of the property, so the grid can automatically apply the sort function according to the type of property inferred by inspecting the type of bean explicitly specified when creating 'Grid'.

It is actually misleading that the downloaded code produces a different result from the online preview.

So I would say it is more a start.vaadin.com issue than a flow or Grid issue

Edit: setSortable(true) makes the sorting indicator visible but it doesn’t work. Using setSortProperty("firstName") makes it visible and it works Thanks @alvarezguille for pointing out

letrthang commented 2 years ago

oh, thanks for sharing. I tried setSortable(true) and it doesn't work. and wonder setSortProperty("firstName") will work. so still a bug :)). Need to fix setSortable(true)

mcollovati commented 2 years ago

It is not a bug. As state in the documentation, setSortable() is used to enable or disable column sorting and toggle the sorter element on and off. To actually apply sort, you should use setSortProperty, setComparator or setSortOrderProvider.

Here's the relevant docs: https://vaadin.com/docs/latest/components/grid/flow/#column-sorting https://vaadin.com/docs/latest/components/grid/flow/#enabling-and-disabling-column-sorting

I apologize for providing wrong information with my first comment.

letrthang commented 2 years ago

Thanks for clarification, then only need fix on start.vaadin.com

mcollovati commented 2 years ago

Thanks for clarification, then only need fix on start.vaadin.com

Thanks for reporting. I'm closing this one, as the issue has been internally notified to the team

mcollovati commented 2 years ago

Transfer to starters repo, to check if demo project should be updated