2
votes

I'm trying to apply formatting to a column in my kendo grid on the DataBound Event. The DataBound event throws a javascript function where i'm trying to select a column and apply some Date formatting. The bound column looks like this:

columns.Bound(c => c.CreatedDate).Title("Submitted on").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains"))).Format("{0: MM/dd/yyyy HH.mm.ss}");

The reason i need to do it there is because i have a button that filters the grid, and upon refreshing the data in the grid it loses the formatting on the date. The current code i have is:

function onDataBound(e) {
        var grid = $("#MyGrid").data("kendoGrid");
        grid.tbody.find('td').each(function () {
            var dataItem = grid.dataItem(this);
            if (dataItem.CreatedDate) {          

                $(this).DoTheFormatting
            }
        });

Need help with the jquery selector

1
How do you identify the column? Is it moveable or does it remain at the same position (index)?Shai

1 Answers

0
votes

You can iterate over the e.sender.tbody.children(), and use the get function to retrieve your columns data instead of using magic numbers on column indexes, like so:

var rows = e.sender.tbody.children();
for (var j = 0; j < rows.length; j++)
{
    var row = $(rows[j]);
    var dataItem = e.sender.dataItem(row);
    if (dataItem.get("CreatedDate"))
    {
        $(this).DoTheFormatting...
    }
}