This is a migrated thread and some comments may be shown as answers.

[Solved] How to access the dataitem value for a cell without knowing the name

4 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bob
Top achievements
Rank 1
Bob asked on 12 Jul 2012, 05:47 PM
I am tackling the UTC issue. We have datetimes in our system that are date only, and they are showing the wrong date based on the timezone. 

I am following this info to resolve it:
http://www.telerik.com/community/code-library/aspnet-mvc/grid/grid-using-utc-time-on-both-client-and-server-sides.aspx 

This works fine, but I want to make the code a bit more generic. I want to just add a class to the column and then have the code convert any date in that column to UTC. 

So I have changed it to this:
function OnRowDataBound(e) {
    if (!e.dataItem.utc) {
        e.dataItem.utc = true;
        $('td.utc', e.row).each(function () {
            e.dataItem.ChangedAt = toUTC(e.dataItem.ChangedAt);
            var display = $.telerik.formatString("{0:G}", e.dataItem.ChangedAt);
            $(this).html(display);
        });
    }
}

But, I need to translate e.dateItem.ChangedAt to the value for the current cell in the each. I'm not quite sure how to do that. Any help is appreciated.

BOb

4 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 13 Jul 2012, 11:06 AM
Hi Bob,

I modified the code library project to be more generic. Please re-download it to see the actual changes.

I hope it fits your needs.

Regards,
Petur Subev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Bob
Top achievements
Rank 1
answered on 13 Jul 2012, 02:08 PM
Thanks Peter. I wonder, how will this work if we have a client template that makes the date a link? I'm thinking we might just have to handle this in the client template?

BOb
0
Daniel
Telerik team
answered on 18 Jul 2012, 01:10 PM
Hello Bob,

The conversion can be handled in the ClientTemplate by calling the to Utc function from the expression:

"<#= toUTC(DateOfOrder)#>"
or in the OnRowDataBound event by replacing the a element content instead of the whole cell content. In both cases you will need to indicate somehow that a different action should be taken for the particular column. An option is to add a specific attribute for the column cells through the HtmlAttributes method.

Kind regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Bob
Top achievements
Rank 1
answered on 18 Jul 2012, 01:38 PM
Yes, I had already just ended up using the toUTC in the client template. It would really be nice if this could be handled out of the box, altough, I know that this product is deprecated... so I guess I will have to request it for the KendoUI MVC grid.

BOb
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Bob
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or