Kendo Treeview Not Updating Remote Data From Datasource

2 posts, 0 answers
  1. Javier
    Javier avatar
    10 posts
    Member since:
    Jun 2013

    Posted 18 Aug 2013 Link to this post

    I'm biding a treeview to a remote data and at this point the data is displayed correctly. The problem: when I change the data in the database and refresh my page, the treeview doesn't reflect the new data. It seems that the treeview is not calling the json action anymore after the first load.

    I tried to work with LoadOnDemand and several other methods, but nothing worked so far. I need to refresh the data because when users drag and drop the nodes, the treeview will be updated in the database.

    ** Code is attached. I also just noticed that it works on Chrome but not IE 10. Thank you for any help.

    I'm following this demo code: http://demos.kendoui.com/web/treeview/remote-data.html

    This is my json action:

    public JsonResult Categories(int? id)
    {

    var categories = from e in db.Categories
    where (id.HasValue ? e.ParentCategoryID == id : e.ParentCategoryID == 1)
    orderby(e.OrderNumber)
    select new
    {
    id = e.CategoryID,
    Name = e.CategoryNames.FirstOrDefault().Name,
    ParentId = e.ParentCategoryID,
    hasChildren = db.Categories.Where(j => j.ParentCategoryID == e.CategoryID).Any()
    }
    ;

    return Json(categories, JsonRequestBehavior.AllowGet);
    }

    This is my treeview code:

    Html.Kendo().TreeView()
    .Name("treeviewcategories")
    .DataTextField("Name")
    .DataSource(dataSource => dataSource
    .Read(read => read
    .Action("Categories", "Settings")
    )
    )
    .Events(events => events
    .Select("onSelect")
    .DragEnd("onDragEnd")
    .Expand("onExpand")
    )
    .DragAndDrop(true) 
  2. Javier
    Javier avatar
    10 posts
    Member since:
    Jun 2013

    Posted 19 Aug 2013 Link to this post

    Resolved by changing the Kendo DataSource call to include the timespan:

    <%:Html.Kendo().TreeView()
    .Name("treeviewcategories")
    .DataTextField("Name")
    .DataSource(dataSource => dataSource
    .Read(read => read
    .Action("ReadCategories", "Settings", new { time = System.DateTime.Now })
    )
    )
    .Events(events => events
    .Select("onSelect")
    .DragEnd("onDragEnd")
    .Expand("onExpand")
    )
    .DragAndDrop(true) 
     

    %>
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top