KendoUI TreeView node select
Currently, KendoUI has problems with select... I thought I'd share a 'workaround'
- Miguel Castillo
HTML
<script src="http://cdn.kendostatic.com/2011.3.1129/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2011.3.1129/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2011.3.1129/styles/kendo.default.min.css">
<script src="http://www.appelsiini.net/download/jquery.jeditable.js"></script>
<ul id='tree'>
<li>Item1
<ul>
<li>Item1.1</li>
<li id='selected'>Item1.2</li>
<li>Item1.3</li>
</ul>
</li>
<li>Item2</li>
<li>Item3</li>
</ul>
JavaScript
$(document).ready(function()
{
// If you want to disable showing the context menu when right clicking
// on the document, the code below would do the trick.
$(document).bind("contextmenu",function(e)
{
return false;
});
var $tree = $("#tree").kendoTreeView(
{
select: function (event)
{
var $item = $(event.node);
console.log( $item );
alert( "selected" );
}
});
// Find the item you want to select...
var $selected = $('#selected');
var $treePath = $selected.parentsUntil($tree, "li");
var treeView = $tree.data('kendoTreeView');
// Expand the tree in order to show the selected item
treeView.expand( $treePath );
// Gotta make both calls...
treeView.select( $selected );
//treeView.trigger( 'select', {node: $selected} );
});