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

how to check checkeboxes based on a condition

1 Answer 749 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Shaun
Top achievements
Rank 1
Shaun asked on 30 Oct 2013, 04:42 PM
Hello,

I've got a treeview which is bound client side and displays checkboxes.
On page load I need to check some of them based on a condition.

element.kendoTreeView({
                        dataSource: data,
                        checkboxes: {
                            name: "checkedData",
                            template: "<input type='checkbox' name='checkedData' value='#= item.text #' />"
                        }
                    });
data is created like this :
data.push({
                    text: item.someName, checked : checked
                });

I can't add a "checked='#= item.checked#'" in the template because this will check everything regardless of what I have in item.checked - it's an html thing.
So how can I achieve this ?

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 31 Oct 2013, 02:51 PM
Hello Stuart,

Since the template is simply an HTML string, you can add the checked attribute conditionally, like this:

"<input type='checkbox' name='foo' value='#: item.text #' #= item.checked ? 'checked' : '' # />"

Here's a live jsBin demo. Note that since you are using a checkbox template, the checkboxes.name configuration option is not needed (since it is used only by the default template).

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