R1_2023

1 Answer 107 Views
Data Source Grid
Dusan
Top achievements
Rank 1
Iron
Dusan asked on 31 Jan 2023, 03:16 PM

Hello, 

I have recently updated from R1 2022 to Kendo UI R1 2023, and now I am facing some backward compatibility issues regarding grid component.

New version does not support optional chaining in grid column field, for example:

columns:[{

field: "object?.property?.property"

}]

such approach throws an exception on sort operation (it works as expected in R2_2022).

Is there a fix foreseen in the near feature?

 

BR

 

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 03 Feb 2023, 12:53 PM

Hello Dusan,

Although such an approach has been working in the previous versions using such syntax is not recommended. Please note that it is not recommended to use complex objects for the column.field as it could lead to complications with multiple grid functionalities including filtering, sorting and grouping.

The appropriate approach would be to bind the field to the parent object and then use a template to display the value of the nested properties. Below is an example:

{ field: "Category", title: "Category", width: "180px", editor: categoryDropDownEditor, template: ({ Category }) => `<strong>${Category.CategoryName}</strong>`  },

Here you will find a Dojo example. 

Regards,
Neli
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Dusan
Top achievements
Rank 1
Iron
commented on 06 Feb 2023, 06:42 AM

Thank you Neli, 

there isn't a problem with displaying the data, for that purpose I have already used custom templates with null chaining.

Like I mentioned above, the problem is with sorting, which used to work pre R1 2023. I would have expected that if some property is missing from object that sorting/filtering operations would assume the default value (i.e. undefined).

To break such a behaviour with a new release is a complete drawback for entire framework.

BR

Neli
Telerik team
commented on 09 Feb 2023, 06:37 AM

Hi Dusan,

Could you please provide more details about the configuration on your side? It will be very helpful if you could modify the dojo example sent in my previous reply to replicates the issue. As I mentioned, using the optional chaining is not recommended, but still having more details about the exact scenario could help us to suggest a possible approach to resolve the issue.

Regards,

Neli

Dusan
Top achievements
Rank 1
Iron
commented on 13 Feb 2023, 06:59 AM

Hi, 

I have edited the Dojo above, it is accessible via following link:

https://dojo.telerik.com/@matej.pinter@poligram.si/EsanuMem/2

Like I have mentioned before, we have used approach like this before and it worked as expected pre R1 2023 release. I have tried to work around this issue by defining a complete schema in the datasource, but the structure of the data is dynamic and complex, so this approach is not acceptable. Null chaining should stay supported.

BR

 

Neli
Telerik team
commented on 16 Feb 2023, 07:08 AM

Hi Dusart,

I will need some additonal time to review the modified example. Thank you very much for your patience.

Regards,

Neli

Dusan
Top achievements
Rank 1
Iron
commented on 16 Feb 2023, 07:13 AM

Hi Neli, 

thank you, take your time.

BR

Neli
Telerik team
commented on 21 Feb 2023, 06:09 AM

Thank you for your patience.

As mentioned in my previous reply although using the optional chaining has been possible in the previous versions it is not recommended to use it. I am sorry for the caused inconvenience with modifying your current code.
The correct approach in such scenarios is using a template. Depending on the scenario you can configure a string template or for more complex scenarios you can add a function.
I modified the Dojo example and added a function for the column that will return an empty string in case the unitMeasure.name is null. Please follow this approach to display data for the fields that might have null value.

Regards,

Neli

Dusan
Top achievements
Rank 1
Iron
commented on 21 Feb 2023, 12:47 PM

Thank you, Neli 

like I have mentioned, there is not a problem with the display (template), I know how to handle this.. there is a problem with build in grid functionality (sorting).

In dojo, try placing sort on column "unit measure", you'll get an exception in console..

BR

Neli
Telerik team
commented on 24 Feb 2023, 11:07 AM

Hi Dusan,

You can set the field option to point to the 'unitMeasure' object and the error will not appear.

In order to sort complex objects you can use custom sort somparer and apply your own logic for the sorting:

- https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/configuration/columns.sortable#columnssortablecompare

 

{ 
                field:"unitMeasure",
                title:"unit measure", 
                template: function(dataItem) {

                  if(dataItem.unitMeasure.name){
                    return "<strong>" + kendo.htmlEncode(dataItem.unitMeasure.name) + "</strong>";
                  }else{
                    return "";
                  }
                },
                sortable: {
                  compare: function(a, b) {                      
		    if (a.unitMeasure.name === undefined) return 1;
                    if (a.unitMeasure.name === b.unitMeasure.name) return 0;
                    return a.unitMeasure.name > b.unitMeasure.name ? 1 : -1;
                  }
                }
              }

 

Here is the modified exaample. 

Regards,

Neli

Dusan
Top achievements
Rank 1
Iron
commented on 27 Feb 2023, 10:55 AM

Thank you Neli, 

Your suggestion is a possible workaround, but in my scenario it requires intense code refactoring  (huge code base).

I tried to stress out the change in the behaviour from R2 2022 to R1 2023, which is a major drawback.

BR

Dusan

Nikolay
Telerik team
commented on 02 Mar 2023, 08:39 AM

Hi Dusan,

I know that sometimes when upgrading from an older to a newer version some adjustments are needed. These are inevitable as the code evolves and the rendering of the component and their performance improves. 

I recommend when upgrading the UI version you check the Breaking changes article that lists most of the changes introduced with each release.

Regards,

Nikolay

 

Tags
Data Source Grid
Asked by
Dusan
Top achievements
Rank 1
Iron
Answers by
Neli
Telerik team
Share this question
or