Cannot get kendo grid data to refresh

1 Answer 360 Views
Grid
Matthew
Top achievements
Rank 1
Matthew asked on 01 Apr 2022, 03:16 PM

I have the following grid and it is properly displaying several records added to the list on page load:


@(Html.Kendo().Grid(IndexModel.logHolder.DataList)
    .Name("logGrid")
    .ToolBar(t => t.Search())
    .Columns(columns =>
    {
    columns.Bound(p => p.CreateDateTime).Title("Date/Time").Format("{0:MM/dd/yyyy hh:mm:ss}").Width(200);
    columns.Bound(p => p.ClientId).Title("Client ID").Width(150);
    columns.Bound(p => p.ClientName).Title("Client Name").Width(150);
    columns.Bound(p => p.Message).Title("Message");
    })
    .Pageable()
    .Sortable()
    .Scrollable(scr=>scr.Height(430))
    .Search(s => {
    s.Field(o => o.CreateDateTime, "eq");
    s.Field(o => o.ClientId, "eq");
    s.Field(o => o.ClientName, "contains");
    s.Field(o => o.Message, "contains");
    })
    .Filterable()
    .DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .ServerOperation(false)
    ))

I have some signalr code that is running and adding items to the list IndexModel.logHolder.DataList.  I can see in my code behind that items are in fact being added to the list.

Immediately after adding an item to the list, I am calling the following javascript to attempt to refresh the data, but it won't refresh:


function refreshData()
    {
        var grid = $("#logGrid").data("kendoGrid");
        grid.dataSource.read();
    }

What am I missing?

 

Thanks

 

 

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 06 Apr 2022, 02:22 PM

Hello Matthew,

Thank you for the provided code snippet.

The read() method of the DataSource makes a request to the remote service unless the Data Source is offline. Since the Grid is bound to the data locally, the read() method will not request the updated data collection.

With that being said, you could switch to remote data binding or pass the updated data collection to the grid's dataSource by using the data() method as per the example below:

function refreshData() {
  var grid = $("#logGrid").data("kendoGrid");
  var updatedData = getNewData(); //get the updated data collection from the server (i.e., through an AJAX request)
  grid.dataSource.data(updatedData);
}

I hope that helps.

 

Regards, Mihaela Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Mihaela
Telerik team
Share this question
or