I am trying to use the toggleExpandCollapse client function and it seems to not work at all. I also am seeing console errors while trying settings to enable the toggleExpandCollapse function.
If I have a TreeList and set ExpandCollapseMode="combined" or "client" I get this error in the console as soon as I try to expand an item. The expanding does work, but collapsing does not, it gives the below error. On top of this if I set the ExpandCollapseMode to "client" the TreeList opens up with ALL items expanded out, but while in Server or Combined mode it does not. What am I doing wrong?
Uncaught TypeError: Cannot read property 'toggleExpandCollapse' of null
at HTMLButtonElement.onclick
Uncaught TypeError: Cannot read property 'Combined' of undefined
at Telerik.Web.UI.TreeListDataItem.initialize (Telerik.Web.UI.WebResource.axd
Here is the JS function I cam calling.
function collapseTree(radTreeListItemID) { debugger; var oTree = $find('<%= RadTreeList1.ClientID %>'); var keys = oTree.get_clientDataKeyNames(); oTree.get_dataItems().forEach(function (a) { var expanded = a.get_expanded(); var title = a.get_element().innerText; var id = a.get_dataKeyValue('ID'); // loop through all the items and locate the one with the matching input datakey. // set expanded to false.. doesnt seem to work.. setting visibility does. if (id == radTreeListItemID && expanded) { debugger; // Make invisible - works //a.set_visible(false); // this should just work but doesnt a.toggleExpandCollapse(); a.set_clientExpanded(false); // doesnt work.. however a work around may be to loop through the child items and make invisible. // onpostback, they are re-written to page anyway.. problem is user control seems to not go away, so youd have to // locate that control in the element and hide too. a.get_childItems().forEach(function (innerItem) { innerItem.set_visible(false); }); } }); };