Home > CMS- Content Management System > Sharepoint > Resize Add-In Parts dynamically in SharePoint Add-Ins

Resize Add-In Parts dynamically in SharePoint Add-Ins

Hello everyone, in this post we will discuss about how to resize Add-in App Part. If you are reading this post first time, I would recommend read following articles

Above my listed article give complete information about App Part/Add In Part

As add-in part render a dynamic content mean that might change its width and height. Due to the dynamic nature of the content, it may not fit in the frame.Might in some cases you need more space as same as parent container. With dynamic content, it could be difficult to specify a fixed size in your add-in part declaration. However, you can resize the frame to fit the content’s width and height.

You can use POST messages from your content webpage to specify the frame’s size. The following JavaScript example shows you how to send a POST message to resize the frame in which your add-in part is hosted. You can call this using the JavaScript method from a JavaScript file.

So here we resize our Accordion app part which have dynamic content from Accordion list.

Steps to resize app part

  • Create an add-in, name Accordion in Microsoft Visual Studio 2013. For more info to create accordion read post SharePoint Hosted Add-In as an App Part
  • So we assume that you have setup Basic Accordion add-in as an App Part. You notice in Elements.xml file by default app part width is 300 and height is 200. In that scenario our app part will show maximum two item as accordion.
  • Now we write code for resize app part. Add following code in accordion.js.

    Call init() function on load in getAccordionListData() method it resize app part on loading.

    Call autoSize() function in every on change event (example click() event) in app part.

  • Final step Run and Deploy the Add-In solution, Now go to the developer site and add App Part on Edit Web Part page. 

    As you see above screen shot On load our Accordion looks very great. On resize  we make accordion div width 100% and height set based on content and on click event.

References

This Article is TAGGED in , , , , , , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">