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

Checking certain nodes on Load of treeview

3 Answers 371 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 01 May 2013, 02:29 PM
Hi,

I have a tree view with a list of nodes which have checkboxes. Once a user checks some of the nodes I persist this information to the database.  I then want to load this info back onto the page.  I cannot seem to get this working.

I'm doing something like:

 $("#treeview").kendoTreeView({
                checkboxes: {                    
                    template: "<input type='checkbox' #= CheckItem(item.IsSet) # />"
                },
                dataSource: inline,
                dataTextField: ["ComponentActionName"],
                loadOnDemand: false
            });

function CheckItem(IsSet) {
            if (IsSet) {
                return "checked='checked'";
            }
            else {
                return "";
            }
        }

This actually works fine, in that the UI shows the correct nodes checked.  The problem is that when I try to save this data again with a function like:

function checkedNodeIds(nodes, checkedNodes) {
            for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].checked) {
                    checkedNodes.push(nodes[i].ComponentActionName);
                }

                if (nodes[i].hasChildren) {
                    checkedNodeIds(nodes[i].children.view(), checkedNodes);
                }
            }
        }

nodes[i].checked shows as undefined for the nodes unless I manually unselect and reselect them.  Is there a property similar to the dataTextField where I can specify the field on the data which indicates if the node should be checked or any other way of achieving this?

Thanks,
Keith

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 02 May 2013, 08:40 AM
Hello Keith,

The data*Field configuration options are not available for item states (checked/enabled/selected). The most robust way to achieve this goal is to transform the data through the schema.parse method, like shown in this jsBin.

Greetings,
Alex Gyoshev
the Telerik team
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
marco
Top achievements
Rank 2
answered on 05 Oct 2016, 12:16 PM

Dear Alex,

The link you provided as a solution is not available anymore.

Could you please tell me how to make some nodes checked by default on loading depending their status in the Database (or in a JSON file)?

0
Alex Gyoshev
Telerik team
answered on 05 Oct 2016, 01:33 PM

Hello Marco,

It appears to have been a temporary problem with the jsBin service. The link is functional now -- the important bit is the definition of the schema.parse function, which maps the properties:

        parse: function(response) {
          for (var i = 0; i < response.length; i++) {
            response[i].checked = response[i].IsSet;
          }
          return response;
        }

 

Regards,
Alex Gyoshev
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
Tags
TreeView
Asked by
Keith
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
marco
Top achievements
Rank 2
Share this question
or