Completed
Last Updated: 28 Aug 2024 14:59 by ADMIN
Release R2.2023-Increment.1(15.Mar.2023)
Filippo
Created on: 20 Jan 2023 13:26
Category: UI for ASP.NET MVC
Type: Bug Report
3
Formatting logic is not executed in the Grid column's HtmlAttributes

Bug report

Regression in R1 2023.

Reproduction of the problem

  1. Set the following HtmlAttributes configuration in a Grid column:
columns.Bound(p => p.OrderDate).HtmlAttributes(new { title = "Order Date: #=kendo.toString(OrderDate, 'dd-MM-yyyy')# " });

Current behavior

kendo.toString is not executed and as a result the date is not formatted. The exact value of the title attribute, as shown above is rendered as title of the cell.

Expected/desired behavior

The logic is executed and the OrderDate value is rendered in the title with the specified format.

Environment

  • Kendo UI version: 2023.1.117
  • jQuery version: x.y
  • Browser: [all]
2 comments
ADMIN
Ivan Danchev
Posted on: 28 Aug 2024 14:59

Hello,

As a result of the CSP compliance initiative, we had to remove all kendo templates from the source of our components, as they are not compatible with the unsafe-eval directive.

From now on, the suggested approach to achieve the same attribute binding result, we deliver a new HtmlAttributes overload that accepts a single string parameter, the name of the JS handler that returns the attributes.

e.g.

// column configuration
columns.Bound(p => p.OrderDate).HtmlAttributes("attributesHandler");

//handler

function attributesHandler(data) {
  return { title: `Order Date: ${kendo.toString(data.OrderDate, 'dd-MM-yyyy')} ` }
}

To achieve the same behavior as before, one could create a global handler and pass the attributes as a parameter of the global handler.
e.g,

// column configuration
.HtmlAttributes("globalAttributesHandler.bind({title:'#=Emaiil#'})")

// global handler

    function globalAttributesHandler(data) {
        const result = {};

        for (const attr in this) {
            result[attr] = kendo.template(this[attr])(data)
        }

        return result;
    }
While the above approach mimics the previous behavior of the attributes configuration, it uses kendo templates, so it is not compatible with the unsafe-eval directive.

Regards,
Ivan Danchev
Progress Telerik

Do you have a stake in the designеr-developer collaboration process? If so, take our survey to share your perspective and become part of this global research. You’ll be among the first to know once the results are out.
-> Start The State of Designer-Developer Collaboration Survey 2024

ADMIN
Ivan Danchev
Posted on: 21 Feb 2023 12:05

Hi,

We plan to include a fix in the upcoming release R1 2023 SP1, which is due in mid March.

As a temporary workaround, the value of the title attribute can be set with js after the Grid is loaded with data:

1. Attach a DataBound event handler to the Grid:

.Events(ev => ev.DataBound("onDataBound"))

2. Execute the following logic in the handler:

function onDataBound(e) {
    var grid = e.sender;

    grid.tbody.find("td[title*='Order Date']").each(function () {
        var row = $(this).parents('tr')
        var dataItem = grid.dataItem(row);

        var content = $(this).attr("title");
        var template = kendo.template(content);
        var title = template(dataItem);
        $(this).attr("title", title);
    });
}

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.