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

Updating a data source not working

1 Answer 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 18 Jul 2018, 09:24 AM

Hello,

I'm having problems getting my grid to show the data I am passing to the datasource.  Although the data is returned it's not displaying inth e gird, I simply get the message "No items to display".  The data passed in is an array of Id's.

var testArray = [17, 18, 19];
 function tabButton(e) {
    console.clear();
    let grid = $("#grid").data("kendoGrid");
    let filter = $(e).data("filter");
 
    grid.dataSource.read({ array: testArray });
    grid.refresh();
}

The controller conditionally handles the presence of an array retunring selected records where true and all records where false.  This means that if there is no array of data it simply returns everything.

public ActionResult GetTabVessels(int[] array, [DataSourceRequest] DataSourceRequest request)
{
    //Make a list
    List<Vessel> vessels = new List<Vessel>();
     
    var vessel = unitOfWork.VesselRepository.Get();
    DataSourceResult result = vessel.ToDataSourceResult(request);
    JsonResult data;
     
    if (array !=null)
    {
        //Populate list based on array of Id's
        foreach (var id in array)
        {
            vessels.Add(unitOfWork.VesselRepository.FindSingleOrDefault(x => x.Id == id));
        }
        //Create Json variable for data source result.
        data = Json(vessels, JsonRequestBehavior.AllowGet);
    }
    else
    {
        data = Json(result, JsonRequestBehavior.AllowGet);
    }
    data.MaxJsonLength = int.MaxValue;
    return data;
}

This grid is straight forward enough

@(Html.Kendo().Grid<Force3Beta.ViewModels.VesselSearchResultsViewModel>()
.Name("VesselGrid")
.Columns(columns =>
{
    columns.Select().Width(50);
    columns.Bound(p => p.Name);
    columns.Bound(p => p.Type);
 
})
.Pageable()
.Sortable()
.Events(ev=>ev.Change("onChange"))
.PersistSelection()
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(p => p.Id))
    .Read(read => read.Action("GetVessels", "Test"))
))

The array function is triggered with a button in the UI for the sake of testing.  I can see in the network tab of the console that requested array of data is returned correctly, I can also see this in the controller as well, but for some reason the grid will not show it.

Can anyone help?

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 20 Jul 2018, 08:04 AM
Hi Allan,

I have examined the provided code and it seems that there is a mismatch in the name of the Read ActionMethod. In the Grid configuration the method that is called is GetVessels and the method in the Controller is GetTabVessels.

Also the tabButton function is referring to a Grid component with id grid and the one in the snippet is named VesselGrid.

Please make sure the names match and see how the behavior changes. In case the behavior persists please send us a runnable sample where it is replicated. This will enable us to examine the issue locally and look for its cause.
 

Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Allan
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or