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

Uncaught TypeError when using k-i-expand or k-i-collapse in Toolbar

2 Answers 95 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
AGB
Top achievements
Rank 1
AGB asked on 30 Mar 2017, 08:40 AM
Hi Guys,

I have just tripped over the following reproducible console error

    Uncaught TypeError: Cannot read property 'expanded' of undefined
        at init._toggleChildren (kendo.all.js:101203)
        at HTMLSpanElement.d (jquery-1.12.3.min.js:2)
        at HTMLDivElement.dispatch (jquery-1.12.3.min.js:3)
        at HTMLDivElement.r.handle (jquery-1.12.3.min.js:3)
    
when using a 'k-i-expand' or 'k-i-collapse' icon in a TreeList toolbar button.

To replicate the problem please run the following dojo

    http://dojo.telerik.com/ERUwiz

and click on the icon within either of the toolbar buttons.

Having a quick trawl through the code shows the problems stems from the TreeView _attachEvents function which is attaching the _toggleButtonClick event to the k-i-expand/k-i-collapse class irrespective of where it is being used.

Therefore I suspect similar problems might be experienced in other controls i.e. TreeView, Grid etc.

Regards
Alan

2 Answers, 1 is accepted

Sort by
0
AGB
Top achievements
Rank 1
answered on 30 Mar 2017, 09:14 AM
A quick workaround to stop the console error is to create two new classes

.k-i-expand-tb:before {
    content: "\e005";
}

.k-i-collapse-tb:before {
    content: "\e001";
}

and use them within the button span.

Regards
Alan
0
Alex Hajigeorgieva
Telerik team
answered on 03 Apr 2017, 07:07 AM
Hello Alan,

The observed behaviour is expected with the current implementation of the k-i-expand icons. The solution is to expand/collapse all items programmatically and use another class for the buttons as you have noted in your second post.

When the icon is clicked, it looks for the model which should be bound to the relevant row and checks its expanded state. Since the icon in the toolbar does not have a model bound to it, the model returns undefined:

var icon = $(e.currentTarget);
var model = this.dataItem(icon);
var event = !model.expanded ? EXPAND : COLLAPSE;
if (!this.trigger(event, { model: model })) {
 this._toggle(model);
}
e.preventDefault();

Thank you for sharing your solution, it will certainly be helpful for anyone who would like to use the expand/collapse icons in the same way. 

Regards,
Alex Hajigeorgieva
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data (charts) and form elements.
Tags
TreeList
Asked by
AGB
Top achievements
Rank 1
Answers by
AGB
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or