Grid integration with Spring

Hi !

I'm having a hard time implementing Syncfusion Grids (on Angular) with Spring as backend.
I've coded a "decoder" for Syncfusion requests on backend side, it deserializes the requests and provides informations for paging, sorting, searching.

Note : I am using JPA's Specifications in order to generate dynamic, auto generated SQL queries. The only thing I have to do is generate the Specifications I then give to JPA, after deserializing the request from the Grid

I am not using a custom adaptor on client side, I prefer to let Syncfusion talk to me as it's meant to do, and will evolve the decoder if someday datamanager changes his approch.

Thing is, I use DTO to provide light objets to the client, and use columns with datasource to requests on child objects.

Here is an example of that logic

On client side : columns
Let's say parent is my main object and child is my sub object, connected by a FK. 

{ 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.

As of now everything is working well, now the problem

When I try to sort a column or search for String in my grid, Syncfusion is sending a request of this type :
{
    "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).


First question, do you approve my logic ? Does it look consistent and respects the datamanager's role ?

Second, is there a way to tell the Grid to use the "entity name + foreignKeyValue" and not the field alone for the requets ? This way my backend will be able to handle any kind of request from the Grid and everything will work fine.


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.


3 Replies

RR Rajapandi Ravi Syncfusion Team April 13, 2021 12:16 PM UTC

Hi Rémy C, 

Greetings from syncfusion support 

Based on your shared code we found that you have used two columns with same field name ‘child.id’. Our Grid component has allowed the unique column then only we can use Grid features (filtering, sorting, grouping, searching, etc..).  

So, we recommend that you do not use duplicate field in more than one column. Please get back to us if you need further assistance on this. 

Regards,
Rajapandi R



RC Rémy C April 14, 2021 03:36 PM UTC

Hello !

So I prepared a simple stackblitz demonstrating the problem.

Stackblitz demonstrating FK Sort Problem (https://stackblitz.com/edit/angular-sf-grid-test1-5rh7kb?file=src/app/sample-grid1/sample-grid1.component.ts)

The project uses demonstration data from odata.org. I display a grid for the entity Order, which is connected to the entity Employee, by EmployeeID field.

In the third column, I display employee names. When I try to sort this column, the request is : .../Orders/?$count=true&$orderby=EmployeeID
So the order is done on the EmployeeID field, but not on the LastName field that is displayed.
As a consequence, the result is that I receive data ordered by EmployeeID, not by LastName. The result is obvious if you sort by order desc : .../Orders/?$count=true&$orderby=EmployeeID%20desc
Now you can see the result, in order of appearence : Dodsworth, Callahan, King

Here is the list of the available employees :

Employees By ID
So the expected order is : Suyama, Peacock, Leverling, King...

Based on this stackblitz, how can I sort Employees by LastName ?


AG Ajith Govarthan Syncfusion Team April 16, 2021 12:22 PM UTC

Hi Rémy C, 

Thanks for the update. 

Query: Based on this stackblitz, how can I sort Employees by LastName 
 
Based on your query you want to sort the foreignkey column using the foreignkey value instead of foreignkey field. By default, in EJ2 Grid we do not have support to sort or filter the foreignkey column with foreignkey values. So, we have logged a feature task for this feature in our Grid. Thank you for requesting this “Need to provide foreignKey adaptor support in EJ2 Grid Component” feature and helping us define it. 

We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts. We have added this feature request to our database, and it will be available in any of our upcoming release.  
  
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.   
  
   
Regards, 
Ajith G. 


Loader.
Up arrow icon