This is a migrated thread and some comments may be shown as answers.

"Realtime" data updates in grid?

1 Answer 504 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Nicklas asked on 19 Jun 2013, 10:34 AM
I have a Grid-component that is populated by a call to a service, from an action in my controller. I was wondering if it is possible to do this continuously, so that it will update the grid with real-time data? 

Right now, my view looks like this;
@model FleetMonitorModel
 
<div class="span12">
    <legend>Fleet Monitor</legend>
        <div>
        @(Html.Kendo().Grid<FleetMonitorModel>()
              .Name("Grid")
              .DataSource(ds => ds
                  .Ajax()
                  .Read(read => read.Action("Get", "FleetMonitor"))
              )
              .HtmlAttributes(new { style = "height:auto;" })
              .AutoBind(true)
              .Columns(columns =>
                  {
                      columns.Template(p => { }).ClientTemplate(" ").Width(310);
                      columns.Template(p => { }).ClientTemplate(" ").Width(250);
                      columns.Template(p => { }).ClientTemplate(" ").Width(150);
                      columns.Template(p => { }).ClientTemplate(" ");
                      columns.Template(p => { }).ClientTemplate(" ").Width(80);
                  })
              .ClientRowTemplate(Html.Partial("_ClientRowTemplate", Model).ToHtmlString())
              .Pageable()
              .Sortable())
    </div>
</div>
And my controller like this:
    private FleetMonitorModel Model { get; set; }
 
    ...      
 
    public ActionResult Get([DataSourceRequest] DataSourceRequest request)
    {
        UnitContract[] listOfUnitsFromService = Client.GetListOfUnits(true);
 
        Model = new FleetMonitorModel()
                    {
                        UnitDetails = GenerateUnitDetails(listOfUnitsFromService.ToList()),
                        Refresh = true
                    };
 
        return Json(Model.UnitDetails.ToDataSourceResult(request));
    }
}

Basically, the service will provide a steady stream of updated data, causing it to be more or less real-time.. All I want to accomplish, is to refresh the grid with my new data and update the graphical elements of my template. Current template is working fine, but data is only refreshed when page is refreshed.

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 21 Jun 2013, 07:54 AM
Hi Nicklas,

 
You can call the dataSource read method to refresh the data from the server using for example the setInterval method:

$(function () {
    var grid = $("#grid").data("kendoGrid");
               
    setInterval(function () {
        grid.dataSource.read();
    }, 9000);
}

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Nicklas
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or