I want to use the ListView to select items, very similar to this example: http://demos.telerik.com/kendo-ui/listview/selection
There are two items that I'm having a problem with. First, I need to be able to select the first item in the list view by default (ie. on new object creation). I found this code in another thread, but it's not working:
var listView = $("#listView").data("kendoListView"); listView.select(listView.element.children().first());Secondly, I need to be able to select an item in the list view by ID (ie. editing an existing object).
This is the JSON I'm sending to the ListView:
{"Icons":[{"Name":"fa-icon-bolt","ID":23},{"Name":"fa-icon-book","ID":3},{"Name":"fa-icon-building","ID":32},{"Name":"fa-icon-building-o","ID":24},{"Name":"fa-icon-calculator","ID":15},{"Name":"fa-icon-car","ID":18},{"Name":"fa-icon-certificate","ID":2},{"Name":"fa-icon-cloud","ID":6},{"Name":"fa-icon-cog","ID":33},{"Name":"fa-icon-desktop","ID":4},{"Name":"fa-icon-diamond","ID":26},{"Name":"fa-icon-exclamation","ID":29},{"Name":"fa-icon-file","ID":25},{"Name":"fa-icon-fire-extinguisher","ID":36},{"Name":"fa-icon-flask","ID":16},{"Name":"fa-icon-globe","ID":11},{"Name":"fa-icon-graduation-cap","ID":1},{"Name":"fa-icon-h-square","ID":20},{"Name":"fa-icon-headphones","ID":12},{"Name":"fa-icon-info","ID":27},{"Name":"fa-icon-laptop","ID":8},{"Name":"fa-icon-line-chart","ID":19},{"Name":"fa-icon-mobile","ID":9},{"Name":"fa-icon-newspaper-o","ID":10},{"Name":"fa-icon-plus","ID":28},{"Name":"fa-icon-puzzle-piece","ID":13},{"Name":"fa-icon-road","ID":34},{"Name":"fa-icon-rocket","ID":35},{"Name":"fa-icon-share-square-o","ID":5},{"Name":"fa-icon-suitcase","ID":30},{"Name":"fa-icon-truck","ID":14},{"Name":"fa-icon-university","ID":7},{"Name":"fa-icon-user","ID":22},{"Name":"fa-icon-user-secret","ID":17},{"Name":"fa-icon-users","ID":21}]}And this is how I'm currently initializing it:
function initIconsView() { var datasource = new kendo.data.DataSource({ transport: { read: { type: "GET", url: "/Controllers/MainController.cfc?method=getIcons", processData: true, dataType: "json", cache: false } }, schema : { type: "json", data: "Icons" } }); $("#icons_list").kendoListView({ dataSource: datasource, selectable: true, template: kendo.template($("#icon_list_template").html()) }); }And the template/HTML:
<script id="icon_list_template" type="text/x-kendo-template"> <div class="icon"> <i class="#: data.Name # fa-icon-2x"></i> </div></script><div class="demo-section k-content wide"> <div id="icons_list"></div></div>Really they're two different facets of the same issue - programmatically selecting an item in the ListView.
