How to change date format in cms data grid? I am using Grid webpart on one of the pages and one of t

NEI CMS asked on October 25, 2016 23:24

How to change date format in cms data grid? I am using Grid webpart on one of the pages and one of the columns is date and I want to display date as MMM, YY. Thanks

Correct Answer

Michal Samuhel answered on October 26, 2016 08:39

Hi,

there is no native support for this kind of request, however you can modify the Grid web part (https://docs.kentico.com/display/K9/Customizing+web+parts). Please open Visual Studio and look for ~\CMSWebParts\Viewers\Documents\cmsdatagrid.ascx.cs. There is method called InitColumns. In this method you can check if the current item is of type datetime and if this would be the case, you can simply modify it according your needs.

There is sample how the code can look like:

BoundColumn col = new BoundColumn(); column = col;

col.DataField = mName;

// Does the name of the column contain "Date" ? If so, let's display it as a short date format if (mName.Contains("Date")) { col.DataFormatString = "{0:d}"; }

0 votesVote for this answer Unmark Correct answer

Recent Answers


Jan Hermann answered on October 26, 2016 09:08

Please use this in your transformation:

<%# GetDateTime("YourDateColumn", "MMM, YY") %>

0 votesVote for this answer Mark as a Correct answer

NEI CMS answered on October 26, 2016 17:32

Thank you @MMichal Samuhel, your approach worked I have cloned the web part and made use of that as editing the cmsdatagrid would apply this change to entire site.

0 votesVote for this answer Mark as a Correct answer

NEI CMS answered on October 26, 2016 17:37

@Jan Hermann I tried to use Transformations before I even submitted this question, I am using Grid webpart on CMS version 8 which is cmsdatagrid and what ever transormation I use or edit under the propert "Selected item transformation:" for this webpart it doesn't work, I guess the webpart is not considering it, Is there some thing we have to do for transformation to work?

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on October 26, 2016 19:39

It's working in ASCX transformations. I have tested it. What kind of transformation do you use?

0 votesVote for this answer Mark as a Correct answer

NEI CMS answered on October 28, 2016 17:42

I used ascx only, I don't know it doesn't recognize it, if possible can you share the transformation you used?

0 votesVote for this answer Mark as a Correct answer

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