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

Best practice when removing DOM elements that may contain Kendo widgets

3 Answers 1346 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jesse
Top achievements
Rank 1
Veteran
Jesse asked on 22 Dec 2018, 02:42 AM

I am working on a page that progressively adds server content as the user provides more information. So there are a lot of chunks of UI being appended and replaced in the UI. I just noticed that when I remove one div, via jquery's .remove function, the div.k-calendar-container.k-popup for some date pickers that were descendants of the div are not being removed and are accumulating at the bottom the page.

In regards to separation of concerns, at the point in my javascript that I am removing the parent element, I don't necessarily want that code to have to know that there are kendo datepickers inside or to have to care about what the contents are at all. Is there a best practice to make sure that kendo widgets are cleaned up/destroyed when they are indirectly removed from the DOM like this?

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 24 Dec 2018, 02:11 PM
Hi Jesse,

The kendo.destroy() method is used to clean up Kendo widgets from a container, so you can then $(container).empty() it. It will remove extra HTML (such as popups) and will delete their client objects. It leaves HTML in the container intact, though, to avoid breaking your entire page, which is why you have to clean up that HTML yourself (you probably already do that).

You can read more about the two ways to use the destroy method (per widget instance and per container) in the following article: https://docs.telerik.com/kendo-ui/intro/widget-basics/destroy.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jesse
Top achievements
Rank 1
Veteran
answered on 26 Dec 2018, 01:31 PM
Ah, the kendo.destroy method can accept any container as a parameter? For some reason I thought it could only destroy all widgets on the page.I will try that out.
0
Marin Bratanov
Telerik team
answered on 26 Dec 2018, 04:04 PM
Sure, Jesse, do things in your own time and if you have questions on this matter, post them here.

Happy holidays!

--Marin

Tags
General Discussions
Asked by
Jesse
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
Jesse
Top achievements
Rank 1
Veteran
Share this question
or