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

Dynamically creating checkbox listview doesn't allow selecting.

3 Answers 389 Views
ListView (Mobile)
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 26 Dec 2012, 03:17 PM
Coming from a jQuery Mobile world when you altered a listview you had to refresh the listview to get things to work. Is there anything I have to do to get dynamically created checkboxes to become selectable? The checkboxes demo works fine but when I try and generate them dynamically they won't allow selected/checked. Below is the sample template I'm trying to use which is simple enough. Thanks for your help.

<script id="position-template" type="text/x-kendo-template">
<li>
    <label>
        <input type="checkbox" value="#= Id #" />
        #= Title #
    </label>
</li>
</script>

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 27 Dec 2012, 01:37 PM
Hi Justin,

It is unclear how do you add the items. The recommended approach is to use the DataSource methods (for example add). In this way the ListView will automatically refresh to add the new item.

In addition please use the checked property of the checkbox input, not the value. As an example:
<input type="checkbox" #= (checked) ? 'checked="checked"' : '' # />

As a general information, the widgets that are used to display data are refreshed automatically when their dataSource changes. Another important thing is that the template provides one-way binding. This means that when the user changes the state of the check box the underlying dataSource item will not change automatically. If that is your aim please hook up to the change event of the check box and set the values manually. The methods you might find helpful are: getByUid (to get the dataItem) and set (to set the new value).

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Justin
Top achievements
Rank 1
answered on 28 Dec 2012, 02:48 AM
Thanks. It was an issue with my datasource and is now working.
0
Martin
Top achievements
Rank 1
answered on 18 Mar 2013, 12:02 PM
Would you may describe WHAT the problem was with your datasource and HOW you solved it? Would be helpful for other people too (like me). Thanks!
Tags
ListView (Mobile)
Asked by
Justin
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Justin
Top achievements
Rank 1
Martin
Top achievements
Rank 1
Share this question
or