We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Passing TimeSpan Value to Entity

Hello,

how can i save a TimeSpan Value in a Grid-Column and send it to Server?

3 Replies

RU Ragavee U S Syncfusion Team June 8, 2016 11:34 AM UTC

Hi Arthur, 

Thanks for your interest in Syncfusion products. 

We analyzed your requirement to bind TimeSpan column to grid and update the modified value to server. We have already discussed on “Binding TimeSpan value to Grid columns” in the below knowledge base link.  


We have achieved your requirement using the Column Template and EditTemplate feature of the Grid.  



Please refer to the below code example. 

<script type="text/javascript"> 
    $.views.converters("value", function(val) { 
    return ej.globalize.format(val,"D2");//get the formatted value 
    }); 
</script> 
 
<div style="margin:30px"> 
    @(Html.EJ().Grid<object>("Grid") 
            .Datasource(d=>d.Json((IEnumerable<object>)ViewBag.data).InsertURL("/Home/Insert").UpdateURL("/Home/Update").RemoveURL("/Home/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor))             
            . . . . 
           .Columns(col => 
            { 
                col.Field("Id").HeaderText("ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Add(); 
                col.Field("TestColumn").Add(); 
                col.Field("Time").HeaderText("Time").EditTemplate(editTemp=>editTemp.Create("create").Write("write").Read("read")).Template("{{:Time.Hours}} : {{value:Time.Minutes}} : {{value:Time.Seconds}}").Add();//show the timespan value using template property; Time property will be obtained as complex object. 
            })   
            .ClientSideEvents(eve=>eve.Create("onGridCreate"))             
    ) 
</div> 
 
<script type="text/javascript"> 
    function onGridCreate(args) { 
        this.model.columns[2].allowEditing = true; //if the column index is undefined, you can get the column object using the getColumnByField or getColumnByHeaderText method and thus update this property. 
    } 
    function create(args) { 
        return $("<input>"); 
    } 
    function write(args) { 
        //convert the element to ejTimePicker control 
        args.element.ejTimePicker({ 
            value: args.rowdata["Time"], 
            interval: 15, 
            timeFormat: "HH:mm:ss", 
            width: "100%" 
        }); 
    } 
    function read(args) { 
        return args.ejTimePicker("getValue");//get the value from the TimePicker control 
    } 
</script> 

We have prepared a sample with the above solution, which can be downloaded from the below location. 


Regards, 
Ragavee U S. 



AR Arthur June 8, 2016 01:52 PM UTC

Thanks, its working fine!:)


RU Ragavee U S Syncfusion Team June 9, 2016 04:22 AM UTC

Hi Arthur, 

  

Thanks for your update. 

  

We are happy that your requirement is achieved. 

  

Regards, 

Ragavee U S. 



SIGN IN To post a reply.
Loader.
Up arrow icon