Sorting definition inside CustomDataAdaptor.getData() for backend-data/query-retrieval is not the same as Grid.sortSettings

Hello,

I use the CustomDataAdaptor for the data query of the Grid. However, I realised that the data query parameters that I send to my backend to query the desired grid data from the database do not correspond to those of the actual grid. For example, it is defined in the grid that the sorting should first take place according to field A and then according to field B. However, the sorting parameters that are sent within CustomDataAdaptor->getData()->options to my backend are as follows: first by field B, then by field A.

I have attached an example project where this is shown:

In the grid, it is defined that sorting should first be by field "CustomerID" and then by field "Freight". However, the query/parameters, stated as json, in the variable CustomDataAdaptor->getData()->options (parameters), which is to be passed on to the backend, describes the sorting as follows: 1. Freight, 2. CustomerID.

Can someone help me here or am I doing something wrong?

https://stackblitz.com/edit/ibnapk-ryxcvd?file=index.js


4 Replies 1 reply marked as answer

LS Laurin S July 12, 2024 01:01 PM UTC

(Hint: to load the data correctly into the grid, please replace line 34 with the following line:

options.onSuccess({ result: JSON.parse(data), count: data.length });

)

The question is still open...



AR Aishwarya Rameshbabu Syncfusion Team July 12, 2024 01:49 PM UTC

Hi Laurin S,


Greetings from Syncfusion support.


After reviewing your inquiry, we have observed that you are utilizing initial sorting with CustomDataAdaptor in the Syncfusion Grid. By default, the data query sort parameters are passed in the order in which the last sorted column will appear as the first query parameter array. Therefore, when processing the data, the sorted query parameter should be reversed. In the Grid, sorting occurs based on a column’s data, and in multiple sorting scenarios, it will be based on the already sorted columns. For more detailed information, please refer to the attached video demonstration where the ‘Ship Country’ column is initially sorted, followed by the sorting of the ‘Order ID’ column based on that. Next, the ‘Order ID’ column is sorted initially and based on that, the ‘Ship Country’ column will be sorted.



Regards

Aishwarya R


Attachment: 189302VideoDemo_e3aca519.zip

Marked as answer

LS Laurin S July 12, 2024 02:26 PM UTC

Ok, I understood that reversing the sorting parameter will solve the problem. But is this really the expected behaviour? Or in other words, can you confirm me that reversing the sorting parameter results always in the correct solution? Or are there some cases, where the sorting parameter has already the correct order...

And why is this "reversing concept" not applied in other parameters too, like in the grouping or aggregates parameters?

Doesn't make much sense to me... but anyway... I will follow your instructions



AR Aishwarya Rameshbabu Syncfusion Team July 16, 2024 06:28 AM UTC

Hi Laurin S,


We can assure that reversing the sorting parameter will consistently yield accurate results, as this functionality is a default feature of our Syncfusion Grid component. This is because in cases of multiple sorting, the sorting is performed based on the columns that have already been sorted. Therefore, we suggest processing the sort-query by reversing the sorted parameters.


Regards

Aishwarya R


Loader.
Up arrow icon