2015-08-25 16 views
8

Ho un controllo RadGrid Telerik che sto vincolando sul lato client, vedo 20+ risultati quindi funziona. La mia data data però è in arrivo in questo modo: 2015-01-30T00:00:00 e ho bisogno di formattarlo in realtà su 2 righe come queste: 1/30/2015<br />12:00:00 AMcome formattare un telerik: GridBoundColumn date field che utilizza un binding lato client?

Il DataFormatString, tuttavia, non sta applicando alcuna modifica alle colonne Data comunque e hanno questo aspetto:

<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> 

Cosa sarebbe necessario per eseguire ciò utilizzando il controllo RadGrid?

Se non può essere eseguito utilizzando il controllo RadGrid, potrebbe essere possibile analizzare i dati JavaScript prima del binding al controllo RadGrid? gridView.set_dataSource(results[0]);

+0

le due righe devono essere nella stessa cella? o può essere 2 righe nella tabella? – Jonathan

risposta

4

Sul RadGrid aggiungere:

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

quindi aggiungere un gestore javascript per esso:

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

Sarà necessario modificare il sopra per ottenere solo il formato della data che si desidera, in questo momento lo farà hh: mm

Spero che questo aiuti!

1

magari utilizzare javascript per aiutare

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 
     } 

è possibile aggiungere a zero per i secondi Milo e falena se ne avete bisogno come ho fatto con ore minuti ect e si può più tutto insieme