Skip to content

DevExpress-Examples/devextreme-components-with-resize-observer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to update a DevExtreme component if an external container state is changed

This example demonstrates how to implement ResizeObserver to update a DevExtreme component layout if an external container visibility/size is changed.

No ResizeObserver

NotWorkingNew

With ResizeObserver

WorkingNew

Implementation details

Implement an ObserverHelper helper class. This class creates a single ResizeObserver instance and contains the following API:

  • The subscribe method allows you to track changes in a parent container for the required component. It accepts the following parameters:

    • component - a widget instance.
    • element - the DOM node (HTML element) whose state you wish to track.
    • resizeAction - the callback that needs to be called.
    • delta - specify this parameter to avoid changing a component if size changes are small.
    • delay - specify this parameter to re-render a component with a delay (e.g., after animation is finished).
  • The disconnect method clears all active subscriptions and removes a ResizeObserver instance.

The resizeCallback function in the helper class is called every time the container size is changed. In this example, we also demonstrated how to reduce the number of calls using the delay and delta parameters.

Files to Review

Documentation

About

This example demonstrates how to implement ResizeObserver to update a DevExtreme component layout if an external container visibility/size is changed.

Topics

Resources

License

Stars

Watchers

Forks