Grid Not Displaying Data

2 posts, 0 answers
  1. Graham
    Graham avatar
    40 posts
    Member since:
    Jul 2012

    Posted 14 Dec 2016 Link to this post

    Here is my grid:

     

    @(Html.Kendo().Grid<tpnconnect.com.Models.Hub.ForkLiftTruck>()
        .Name("ForkLiftTruckGrid")
        .Columns(columns =>
        {
            columns.Bound(f => f.ForkLiftTruckID).Title("ID").Hidden(true);
            columns.Bound(f => f.Deleted).Title("Deleted");
            columns.Bound(f => f.HubDepotNumber).Title("Depot Number").Locked(true);
            columns.Bound(f => f.HubID).Title("Hub ID").Hidden(true);
            columns.Bound(f => f.TruckNumber).Title("Truck Number");
        })
        .Editable(editable => editable.Mode(GridEditMode.InLine))
                .ToolBar(toolbar => toolbar.Create())
                .Pageable()
                .Sortable()
                .Filterable()
                .Scrollable()
                .HtmlAttributes(new { style = "height:720px;" })
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Events(events => events.Error("FLT_Grid_error_handler"))
                    .Model(model => model.Id(d => d.ForkLiftTruckID))
                    .PageSize(16)
                    .ServerOperation(false)
                    .Create(update => update.Action("AddForkLiftTruck", "Warehouse"))
                    .Read(read => read.Action("GetForkLiftTrucks", "Warehouse").Type(HttpVerbs.Get))
                    .Update(update => update.Action("EditForkLiftTruck", "Warehouse"))
                )
    )

     

    Here's my ForkLiftTruck definition:

     

    namespace tpnconnect.com.Models.Hub
    {
        public class ForkLiftTruck
        {
            public int ForkLiftTruckID { get; set; }
            public int TruckNumber { get; set; }
            public int HubID { get; set; }
            public string HubDepotNumber { get; set; }
            public bool Deleted { get; set; }
        }
    }

     

    Here's my controller code:

    [HttpGet]
    public ActionResult GetForkLiftTrucks([DataSourceRequest]DataSourceRequest request)
    {
        int depotID = Utilities.GetUserDepotID();
        List<Models.Hub.ForkLiftTruck> flts = new List<Models.Hub.ForkLiftTruck>();
     
        using (WarehouseService.WarehouseServicesClient ws = new WarehouseService.WarehouseServicesClient())
        {
            var serviceFLTs = ws.GetForkLiftTrucks(depotID);
     
            foreach (var serviceFLT in serviceFLTs)
            {
                Models.Hub.ForkLiftTruck flt = new Models.Hub.ForkLiftTruck()
                {
                    Deleted = serviceFLT.Deleted,
                    ForkLiftTruckID = serviceFLT.ForkLiftTruckID,
                    HubDepotNumber = serviceFLT.HubDepotNumber,
                    HubID = serviceFLT.HubID,
                    TruckNumber = serviceFLT.TruckNumber
                };
     
                flts.Add(flt);
            }
     
            var data = flts.ToDataSourceResult(request);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
    }

     

    Attached files:

     

    1. screenshot of Chrome's network traffic inspector for the response to the grid's read request

    2. screenshot of the Kendo UI listener seeing the data bind event

  2. Graham
    Graham avatar
    40 posts
    Member since:
    Jul 2012

    Posted 14 Dec 2016 Link to this post

    Removing the lock on the depot number column and using model fields to determine which columns can be edited has done the trick. Updated grid below:

     

    @(Html.Kendo().Grid<tpnconnect.com.Models.Hub.ForkLiftTruck>()
        .Name("ForkLiftTruckGrid")
        .Columns(columns =>
        {
            columns.Bound(f => f.ForkLiftTruckID).Title("ID").Hidden(true);
            columns.Bound(f => f.Deleted).Title("Deleted");
            columns.Bound(f => f.HubDepotNumber).Title("Depot Number");
            columns.Bound(f => f.HubID).Title("Hub ID").Hidden(true);
            columns.Bound(f => f.TruckNumber).Title("Truck Number");
            columns.Command(command => { command.Edit(); });
        })
        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .ToolBar(toolbar => toolbar.Create())
        .Pageable()
        .Sortable()
        .Filterable()
        .Scrollable()
        .HtmlAttributes(new { style = "height:620px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Events(events => events.Error("FLT_Grid_error_handler"))
            .Model(model =>
                {
                    model.Id(d => d.ForkLiftTruckID);
                    model.Field(f => f.Deleted).Editable(true);
                    model.Field(f => f.HubDepotNumber).Editable(false);
                    model.Field(f => f.TruckNumber).Editable(true);
                }
            )
            .PageSize(16)
            .ServerOperation(false)
            .Create(update => update.Action("AddForkLiftTruck", "Warehouse"))
            .Read(read => read.Action("GetForkLiftTrucks", "Warehouse").Type(HttpVerbs.Get))
            .Update(update => update.Action("EditForkLiftTruck", "Warehouse"))
        )
    )
Back to Top