Serenity: Date and DateTime formatting

Created on 9 Mar 2016  路  9Comments  路  Source: serenity-is/Serenity

Hi Volkan,
I'm trying to customize date and datetime format both in a grid and in a dialog, but without any success...I was playing with DateTimeFormatter and DisplayFormat attributes but I'm doing something wrong because the date and datetime are always displayed in the same format...
Moreover, there is any way to hide the date/time picker when such fields is ReadOnly(true) ?
Or it's better to force the field to use another editor type? I tried to force a datetime field with a StringEditor but once again I don't know how to control the output format (that in such case in something like "dateTtime".

Edit: DisplayFormat do the job on grids.

Thanks
Regards

Most helpful comment

It's important (at least for us) to give users the feeling that such field will never be editable.

Thanks

All 9 comments

Columns and editors are different things. DisplayFormat works on columns. Editors uses server Culture, not UI culture. This culture info is transferred to script side from LayoutHead.cshtml.

< script type="application/json" id="ScriptCulture">@Html.Raw(Serenity.JSON.Stringify(new ScriptCulture()))</ script>

You may change culture in web.config, or override ScriptCulture settings transferred to client side here, e.g. new ScriptCulture { DateFormat = .... }

Copy that!
But which is the right approach to show a date/datetime readonly calculated field on a dialog (for example LastUpdate or Created) with a custom format and without (I mean hidden and not disabled) the time picker icon?

Thanks in advance

ReadOnly should hide button, what is version you are using??

Not hide disable actually

Exactly the picker is disabled and not hidden.
I'm trying to hide the picker because such date/datetime fields are always readonly in my dialog...perhaps I can force a StringEditor? In that way I obtain a disabled control without picker (obviously), but I haven't control on the output format (that is something like "dateTtime").
Any suggestion to achieve that result/behaviour?

Edit: I'm using version 1.9.17

Thanks in advance
Regards

I don't understand why its so important to hide picker image but you can hide it with CSS
.s-MyDialog .MyReadOnlyField .ui-datepicker-trigger { display: none }
Check classes, i don't remember what was it

It's important (at least for us) to give users the feeling that such field will never be editable.

Thanks

In hiding the disable button.. add a stringfield in your row then pass the value of the datetime through expression..

Thanks @volkanceylan it works,

<script type="application/json" id="ScriptCulture">
    @Html.Raw(Serenity.JSON.Stringify(new ScriptCulture { DateFormat = "dd/MM/yyyy" }))
</script>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kilroyFR picture kilroyFR  路  3Comments

gfo2007 picture gfo2007  路  3Comments

JohnRanger picture JohnRanger  路  3Comments

chintankukadiya18 picture chintankukadiya18  路  3Comments

Shraddha996 picture Shraddha996  路  3Comments