how to check checkeboxes based on a condition

2 posts, 0 answers
  1. Shaun
    Shaun avatar
    10 posts
    Member since:
    Dec 2010

    Posted 30 Oct 2013 Link to this post


    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.

                            dataSource: data,
                            checkboxes: {
                                name: "checkedData",
                                template: "<input type='checkbox' name='checkedData' value='#= item.text #' />"
    data is created like this :
                        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 ?
  2. Alex Gyoshev
    Alex Gyoshev avatar
    2515 posts

    Posted 31 Oct 2013 Link to this post

    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 configuration option is not needed (since it is used only by the default template).

    Alex Gyoshev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top