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

How to set Checkbox by default checked in treeview

1 Answer 511 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Krunal
Top achievements
Rank 1
Krunal asked on 29 Mar 2014, 08:51 AM
Hi

I am trying to set treeview with checkbox and there are some check box are by default checked , here my data source value:-
[{"id":12,"Name":"Shirts","hasChildren":false,"Checked":true}
,{"id":13,"Name":"Jeans","hasChildren":false,"Checked":false},
{"id":14,"Name":"Shoes","hasChildren":false,"Checked":true},
{"id":15,"Name":"Apparel accessories","hasChildren":false,"Checked":false}]


and my view page code:--

$(document).ready(function() {
                        $("#category-treeview").kendoTreeView({
                            dataSource: categories,
                            dataTextField: "Name",
                            checkboxes: true
                    });
                });

but i no one checkbox is selected why?

Can any advice how to solve this?

Regards,
vinit

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 01 Apr 2014, 12:53 PM
Hello Vinit,

By default, the checkboxes are bound to a field named "checked", however there is no such field in the DataSource items. There are two solutions:
  • Rename the "Checked" field to "checked", as JavaScript is case sensitive 
  • Specify the DataSource's model and create a "checked" field that takes its value from "Checked". For example: 
        $("#category-treeview").kendoTreeView({
            dataSource: new kendo.data.HierarchicalDataSource({
              data: categories,
              schema: {
                model: {
                  fields: {
                    checked: {from: "Checked", type: "boolean"}
                  }
                }
              }
            }),
            dataTextField: "Name",
            checkboxes: true
    });


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
General Discussions
Asked by
Krunal
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or