how to check checkeboxes based on a condition

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

    Posted 30 Oct 2013 Link to this post

    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 ?
  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 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 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!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top