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?