Templates in Column attributes no longer supported?

1 Answer 331 Views
Grid
Erik
Top achievements
Rank 1
Iron
Iron
Erik asked on 22 Mar 2023, 03:46 PM

As recently as version 2022.3.1109, I could set a grid column attribute (e.g. class) to a template and easily get conditional formatting like different cell background colors depending on value:

    columns: [
                    { field: "OrderDate", title: "Order Date", format: "{0:MM/dd/yyyy}" },
                    { field: "Freight",  
                      attributes: { 
                                    class: "#: ClassFromFreight(data.Freight) #" 
                                  } 
                    }      

DEMO

Since 2023.1.117, this no longer seems to work. Was this an intentional change? Is there another way to do this now?

DEMO with 2023.1.314

Erik
Top achievements
Rank 1
Iron
Iron
commented on 22 Mar 2023, 04:19 PM | edited

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 27 Mar 2023, 01:38 PM

Hello Erik,

There are some changes to the kendo templates evaluation rendering and the attributes logic has changed. Here is how the new attributes setup shall happen:

https://github.com/telerik/kendo-ui-core/issues/7174#issuecomment-1473687487

I have modified the Dojo demo based on the shared server response and columns binding:

Dojo: https://dojo.telerik.com/OqInOluP

{ field: "Freight",  
  attributes: attributesHandler
 }
...
function attributesHandler(data) {
   return { class: `${ClassFromFreight(data.Freight)}` }
}

Please let me know if you have any questions.

Regards,
Nikolay
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.

Erik
Top achievements
Rank 1
Iron
Iron
commented on 27 Mar 2023, 02:38 PM

Thank you! That works for me.
Tags
Grid
Asked by
Erik
Top achievements
Rank 1
Iron
Iron
Answers by
Nikolay
Telerik team
Share this question
or