How to format telerik: date field GridBoundColumn that uses client-side binding?

I have a Telerik RadGrid control that I snap on the client side, I see 20 results, so it works. My date, date, however, is as follows: 2015-01-30T00:00:00 , and I need to format it on two lines as follows: 1/30/2015<br />12:00:00 AM

However, DataFormatString does not apply any changes to Date columns, and they look like this:

 <telerik:GridBoundColumn DataField="StartDate" UniqueName="StartDate" HeaderText="Start" SortExpression="StartDate" DataFormatString="{0:MM/dd/yyyy hh:mm}" HtmlEncode="false"></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="StopDate" UniqueName="StopDate" HeaderText="Stop" SortExpression="StopDate" DataFormatString="{0:MM/dd/yyyy hh:mm}" HtmlEncode="false"></telerik:GridBoundColumn> 

What do you need to accomplish this with the RadGrid control?

If this cannot be done using the RadGrid control, can it be possible to parse the JavaScript data before binding to the RadGrid control? gridView.set_dataSource(results[0]);

+8
javascript data-binding telerik
source share
2 answers

On your RadGrid add:

<ClientSettings> <ClientEvents OnRowDataBound="RadGrid1_RowDataBound" /> </ClientSettings>

Then add a javascript handler for it:

 function RadGrid1_RowDataBound(sender, args) { var dateValue = new Date(args.get_dataItem()["StartDate"]); args.get_item().get_cell("StartDate").innerHTML = dateValue.getHours() + ":" + dateValue.getMinutes(); } 

You will need to modify the above to get only the date format you want, at the moment it will do hh: mm

Hope this helps!

+4
source share

maybe use javascript to help

  function displayTime { var startDate = new Date(); var month = getMonth() + 1; var day = getDate(); var year = .getFullYear(); var hours = getHours(); if (hours<10) { hours = "0"+hours} var minutes = getMinutes(); if (minutes<10) { minutes = "0"+minutes} var seconds = getSeconds(); if (seconds<10) { seconds = "0"+seconds} var milo = getMilliseconds(); return month + // you get the idea } 

you can add zero for milo seconds and moles if you need it, as I did with hours in minutes, etc., and you can plus everything together

+1
source share

All Articles