Treeview dataSource how to refresh?

8 posts, 1 answers
  1. zheng
    zheng avatar
    2 posts
    Member since:
    Jun 2013

    Posted 03 Jul 2013 Link to this post

    @(Html.Kendo().TreeView()
    .Name("treeview")
    .TemplateId("treeview-template")
    .HtmlAttributes(new { @class = "demo-section" })
    .DataTextField("name")
    .DataUrlField("Link")
    .DataSource(dataSource => dataSource
    .Read(read => read
    .Action("GetTreeMenu", "Menu")
    )
    )
    )
    How can i refresh the datasource?
    When i  changed the menu'name or del it ,the db has changed ,but not changed the monitor?
    i don't know how to refresh th datasource?
     
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 05 Jul 2013 Link to this post

    Hello Zheng,


    You could refresh the dataSource by calling it's read method.
    E.g.
    var tree = $("#treeview").data("kendoTreeView");
    tree.dataSource.read();

    Please let me know if this was the information that you were looking for.

     

    Regards,
    Dimiter Madjarov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. zheng
    zheng avatar
    2 posts
    Member since:
    Jun 2013

    Posted 06 Jul 2013 Link to this post

    Hi Dimiter ,
    Thank you! Sorry to reply a little late .
    tree.dataSource.read(); But under the ie that it is no use !
     So i want to at the end of url add a time stamp,
    .Read(read => read.Action("GetTreeMenu", "Menu"))
    //change like this
    //.Read(read => read.Action("GetTreeMenu?time="+DateTime.Now.ToString()+"&"+, "Menu"))
    //but is no work
    At last I through get the js code is compiled.
    changed the url like this("GetTreeMenu?time="+ new Date().getTime() +"&"),
     Then To replace it himself ! Now it can refresh.
    If you have a good solution, please tell me, thank you !
    Thanks,
    Zheng
     

  5. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 09 Jul 2013 Link to this post

    Hello Zheng,


    You could pass the additional data (i.e. the timestamp) either using object route values
    E.g.
    .Read(read => read.Action("GetTreeMenu", "Menu", new { name = "test", id = 2 }))

    OR
    via the Data method, which specifies the JavaScript function, which will return the additional parameters.
    E.g.
    .Read(read => read.Action("GetTreeMenu", "Menu").Data("additionalInfo"))

    function additionalInfo() {
        return {
            name: "test",
            id: 2
        }
    }

    In both cases, you should add the two additional parameters to you Action.
    E.g.
    public JsonResult GetTreeMenu(... , string name, int id) {...}

    I hope that these approaches will work in the current scenario. I wish you a great day!

     

    Regards,
    Dimiter Madjarov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Eugene
    Eugene avatar
    1 posts
    Member since:
    Oct 2010

    Posted 26 Jul 2013 Link to this post

    Hi Dimiter, is there a way to add the Data parameters based on the node that is currently being expanded? Can the read data be set from client side expand event?
    @(Html.Kendo().TreeView()
                .Name("treeEquipmnetMakes")
                .HtmlAttributes(new { @class = "treeEquipmentMakes" })
                .DataTextField("Name")
                .DataSource(dataSource => dataSource
                    .Read(read => read.Action("EquipmentModels", "Admin"))
                )           
                .Events(e => e.Select("treeItemSelect")
                              .Change("treeItemChange")
                              .Expand("treeItemExpand")
                )
     
            )
     
            <script>
                function treeItemExpand(e) {
                    var dataItem = this.dataItem(e.node);
                    var dataText = "type=" + dataItem.ModelType;
                    var ds = e.sender.dataSource;
     
                    ds.options.data.push(dataText);
                }


    Thanks
    Eugene
  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 29 Jul 2013 Link to this post

    Hello Eugene,


    I answered this question in the support thread. I'll post the code here for convenience too. Yes, you could achieve this if the additionalInfo is a global object which is accessible in both functions.
    E.g.
    <script>
        var additional = {};
      
        function expand(e) {
            var age = this.dataItem(e.node).Age;
            var name = this.dataItem(e.node).Name;
            additional.name = name;
            additional.age = age;
        }
      
        function additinalData() {
            return additional;
        }
    </script>


    Regards,
    Dimiter Madjarov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Shah
    Shah avatar
    1 posts
    Member since:
    Aug 2012

    Posted 10 Mar in reply to Dimiter Madjarov Link to this post

    Hi Dimiter,

    I have added new record to treeview from context menu, the newly created record is now populated in treeview by using

    tree.dataSource.read();

    However, this make the treeview collapsed, how should we keep the treeview being expanded even aftre new record inserted?

     

    code:

    $.ajax({
                        type: "POST",
                        url: form.attr('action'),
                        data: form.serialize(),
                        success: function (data) {
                            $("#divLoading").hide();
                            if (data.result) {
                                $("#dialog").dialog('close');
                                
                                var treeview = $("#treeview").data("kendoTreeView");
                                treeview.dataSource.read();
                                //var node = treeview.findByUid(selectedNode.uid);
                                //ExpandNode(node);
                                //treeview.select(node);
                                //currentSelectedNode = node;
                             
                               
                            } else {
                                // alert('false');
                                alert(data.message);
                            }
                        },
                        dataType: 'json'
                    });

  9. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 11 Mar Link to this post

    Hello Shah,

    A possible solution for the current case is demonstrated in the following sample project.

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready