بعد از صدا زدن فایلهای مورد نیاز کندو، این فایل جاوااسکریپتی را هم به پروژه اضافه کنید. بیشتر توابع تست شده و جواب گرفته و فکر نکنم مشکلی باشد؛ هر چند عیب یابی آن هم ساده است و مشکلی برای برطرف کردن آن وجود ندارد و هر تابع دو یا سه خط بیشتر نیست.
معرفی توابع
var treeview; function FindTreeViewObj(objName) { treeview = $(objName).data("kendoTreeView"); }
FindTreeViewObj("#treeview");
function GetSelectedNode() { return treeview.select(); }
GetSelectedNode();
function DisableSelectedNode() { treeview.enable(GetSelectedNode(), false); }
DisableSelectedNode();
function EnableSelectedNode() { treeview.enable(GetSelectedNode(), true); }
EnableSelectedNode();
function EnableAllNodes() { treeview.enable(".k-item"); }
EnableAllNodes();
function ExpandAllNodes() { treeview.expand(".k-item"); }
ExpandAllNodes();
function CollapseAllNodes() { treeview.collapse(".k-item"); }
CollapseAllNodes();
function RemoveSelectedNode() { treeview.remove(GetSelectedNode()); }
RemoveSelectedNode()
function FilterTreeView(filterText) { if (filterText !== "") { treeview.dataSource.filter({ field: "text", operator: "contains", value: filterText }); } else { treeview.dataSource.filter({}); } }
FilterTreeView('my node')
function SortTreeView(sortType) { treeview.dataSource.sort({ field: "text", dir: sortType }); }
SortTreeView('asc'); SortTreeView('desc');
function GetSelectedDataItem() { return treeview.dataItem(GetSelectedNode()); }
GetSelectedDataItem();
function GetSelectedNodeId() { var data = GetSelectedDataItem(); return data.id; }
GetSelectedNodeId();
function GetSelectedNodeText() { var data = GetSelectedDataItem(); return data.Name; }
GetSelectedNodeText();
function SetSelectedNodeText(value) { var node = GetSelectedNode(); treeview.text(node, value); }
SetSelectedNodeText('new value');
function GetNodeByText(text) { return treeview.findByText(text); }
GetNodeByText('mynode');
function GetNodeByText(id) { return treeview.findByUid(id); }
GetNodeByText(4);
function InsertAfter(item, nextItem) { treeview.insertAfter({ text: "item" }, GetNodeByText(nextItem)); }
InsertAfter('new item', 'old item')
function MoveToAfter(firstItem, secondItem) { treeview.insertAfter(GetNodeByText(firstItem), GetNodeByText(secondItem)); }
MoveToAfter('firstItem', 'secondItem');
function InsertBefore(item, nextItem) { treeview.insertBefore({ text: "item" }, GetNodeByText(nextItem)); } function MoveToBefore(firstItem, secondItem) { treeview.insertBefore(GetNodeByText(firstItem), GetNodeByText(secondItem)); }
InsertBefore('new item', 'old item'); MoveToBefore('firstItem', 'secondItem');
function GetParent(node) { return treeview.parent(node); }
GetParent(GetSelectedNode());
function Toggle(node) { treeview.toggle(node); }
Toggle(GetSelectedNode());
function NewNode(nodeText, nodeValue, selectedNode) { treeview.append({ Name: nodeText, Id: nodeValue }, selectedNode); }
NewNode('new node', 1, null); NewNode('new sub node', 2, GetSelectedNode());