{ uid: 'id', field: 'id', headerText: 'ID', isPrimaryKey: true, visible: false }, { field: 'property', headerText: 'Property', allowFiltering: true, allowSorting: true }, { field: 'child.id', headerText: 'Child Name', foreignKeyValue: 'name', foreignKeyField: 'id', dataSource: this.childDataSource, allowEditing: true, allowFiltering: true, allowSorting: true} { field: 'child.id', headerText: 'Child Label', foreignKeyValue: 'label', foreignKeyField: 'id', dataSource: this.childDataSource, allowEditing: true, allowFiltering: true, allowSorting: true} |
I define 4 columns, ID, property which is a field of parent, and child.id, allowing this.childDataSource to request on the concerned controller providing needed child informations (name and id). Note that there's two child.id columns, one displaying child's name, the other displaying child's label, and so I cannot tell the backend to map "child.id" to "child.name", since it can be either name or label, or anything else.
On server side : objects
@Entity public class Parent { @Identity private Long id; private String property; @ManyToOne private Child child; } @Entity public class Child { @Identity private Long id; private String name; private String label; } |
Still server side : DTO
public class ParentDto { private Long id; private String property; private ChildDto child; } public class ChildDto { private Long id; } |
Note that, in this case, the only information needed for child on client side is his id which is then used to request Child Controller with this.childDataSource.
{ "requiresCounts": true, "sorted": [ { "name": "child.id", "direction": "ascending" } ], "skip": 0, "take": 250 } |
Thing is, I clicked on my column child.id but this column is displaying the child name,not his id. And so, my backend will sort on the ids, when the needed sort is on the names.
Same problem with search, if I search for a String, my backend will understand that this String will have to be compared to ids, which are Long, I end up with a Cast Exception (maybe my backend code can be improved to prevent that, but that's another subject).
I can provide you with examples, but since it involves backend serialization, DTO, JPA, etc, it's not that easy, I would have to simulate the case, but I still can do if you feel like it's needed.
Thank you in advance, I'm looking forward to your reply.