UniGrid - DateTime column formatting

Dave Forster asked on February 3, 2016 13:40

How can i set the format of a unigrid column that is displaying a DateTime property value (from a custom module class).

The Site wide culture settings are all configured correctly (for en-GB) and every other unigrid in the admin area seems to display its dates in the desired UK format - dd/MM/yyyy HH:MM (for example the Event Log grid).

However, when I display my own data grid its using the US format - MM/dd etc

Image Text

There doesn't appear to be any additional formatting rules/transformations being applied to the other unigrids in the admin area so i'm confused as to why mine is displaying US format.

Any help appreciated.

Recent Answers


Joshua Adams answered on February 3, 2016 15:15

Have you tried setting the external source name on the column and in the external databound event, formatting the date and returning your formatted value? That should take care of that issue and allow you to have full control over what is shown.

0 votesVote for this answer Mark as a Correct answer

Dave Forster answered on February 3, 2016 15:22

Hi Joshua,

as it happens, that's exactly what I've done.

protected object grid_OnExternalDataBound(object sender, string sourceName, object parameter)
{
    switch (sourceName)
    {
        case "datetime":
            DateTime dt = (DateTime)parameter;
            return dt.ToString("dd/MM/yyyy HH:MM");
    }

    return parameter;
}

Although I'm confused why I've had to take this extra (and seemingly unnecessary) step. None of the other module grids I've looked at in the project seem to bother with this.. the dates just display correctly on those

1 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on February 3, 2016 16:02

Have you tried debugging and seeing if it goes into your method?

0 votesVote for this answer Mark as a Correct answer

Dave Forster answered on February 3, 2016 16:08

Sorry, I should have made it clearer.

My method is working and solves the problem... I just don't see why i need this additional code. I expect it to behave like every other unigrid that displays dates correctly (without hooking into OnExternalDataBound)

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on February 3, 2016 16:18

Ahh, in that case...there is a set of items that you can set the externalsourcename to that will display the date such as #date, #time, userdatetime, and #usertime. See if one of those will work. It should be similar for version 9 also I think.

https://docs.kentico.com/display/K8/Reference+-+UniGrid+definition

0 votesVote for this answer Mark as a Correct answer

Dave Forster answered on February 4, 2016 15:15

Tried all the date/time related options for ExternalSourceName.. made no difference.

Will just have to stick with the code for now

0 votesVote for this answer Mark as a Correct answer

Quentin Heroguel answered on May 16, 2018 16:39

Actually I did the same error and in fact you don't need additional code for your custom UniGrid. You just need to set the UI culture you want into the Localization > Cultures then check the option Is UI Culture of the chosen culture. Once it's done you can set the default UI culture to desired users into the Users application (Into General tab). For me it was the administrator.

source: https://docs.kentico.com/k10/multilingual-websites/setting-up-a-multilingual-user-interface

To see the effect you need to clear cache or open your website into incognito mode.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.