Skip to main content

How to set Apply button and make the component full width in SharePoint SPFx

How to Set Apply Button in SPFx Property Pane - Step-by-Step Guide

How to Set Apply Button in SPFx Property Pane - Step-by-Step Guide

Author: Vishal Thakur

Published: August 2021

The SharePoint Framework (SPFx) offers a rich UI and flexibility for creating dynamic and responsive web parts. One of the powerful features is the ability to add an Apply button in the SPFx property pane. This button allows you to apply changes made in the property pane asynchronously, eliminating the need to refresh the page to see updates. In this guide, we'll walk you through the steps to implement this feature.

Introduction

The SPFx framework is packed with rich UI capabilities, allowing developers to create dynamic and responsive web parts. One such feature is the Apply button in the property pane. This button enables asynchronous updates, so you can see changes without refreshing the page. Let's dive into how you can implement this in your SPFx solution.

Step-by-Step Guide

Step 1: Create an SPFx Solution

First, create an SPFx solution using the following command in PowerShell or Visual Studio Code:

yo @microsoft/sharepoint

Name your solution (e.g., dynamic-property) and select the web part options as needed.

SPFx Solution Creation

Step 2: Build the Solution

After creating the solution, run the build command:

gulp build

Step 3: Modify the WebPart File

Open the DynamicControlWebPart.ts file and add the following code to enable the Apply button:

protected get disableReactivePropertyChanges(): boolean { return true; } protected onAfterPropertyPaneChangesApplied(): void { ReactDom.unmountComponentAtNode(this.domElement); this.render(); }

This code disables reactive property changes and ensures the web part re-renders after applying changes.

Step 4: Add Property Pane Configuration

Next, configure the property pane with fields and buttons. Here's an example:

protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { return { pages: [ { header: { description: "Configure your web part" }, groups: [ { groupFields: [ PropertyPaneTextField('description', { label: "Description" }), PropertyPaneButton('btn', { text: "Apply", onClick: this.onApplyButtonClick }) ] } ] } ] }; }

Step 5: Deploy and Test

Once the code is added, build and deploy your solution. You can test it locally or deploy it to a SharePoint environment. The Apply button will now appear in the property pane, allowing you to apply changes without refreshing the page.

How to Make SPFx WebPart Full Width

To make your SPFx web part full width, follow these steps:

Step 1: Modify the Manifest File

Open the DynamicControlWebPart.manifest.json file and add the following property:

"supportsFullBleed": true

Step 2: Build and Deploy

After adding the property, rebuild your solution and deploy it. The web part will now support full-width rendering.

Full Width WebPart

Conclusion

By following these steps, you can easily add an Apply button to your SPFx property pane and make your web part full width. These features enhance the user experience by providing dynamic content updates and responsive design. If you found this guide helpful, feel free to leave a comment below!

Download the Source Code: Click here

Related Articles:

Thank you for reading! If you have any questions or feedback, please leave a comment below.

Comments

  1. You are giving such interesting information about Full Stack. It is great and beneficial info for us, I really enjoyed reading it. Thankful to you for sharing an article like this.

    ReplyDelete

Post a Comment

Popular posts from this blog

Power Apps modern driven app Interview Question and answer

Power Apps Modern Driven App: Questions and Answers Power Apps Modern Driven App: Questions and Answers Power Apps modern driven apps are low-code/no-code platforms that enable users to create custom applications. Below are some common questions and detailed answers to help you understand their capabilities and applications. Question 1: What is a Power Apps modern driven app? Answer: A Power Apps modern driven app is a low-code/no-code application development platform provided by Microsoft. It allows users to create custom applications that can run on various devices and platforms without extensive coding. These apps are built using a visual interface and can integrate with different data sources. Question 2: What are the key components of a Power Apps modern driven app? Answer: The key components of a Power Apps modern driven app are: Screens: Serve as the user interface for the app, including layouts, ...

SPFX Interview question for 2023

SPFx Interview Questions for 2023 SPFx Interview Questions for 2023 Author: Vishal Thakur Question 1: What is SharePoint Framework (SPFx)? Answer: SharePoint Framework (SPFx) is a development model introduced by Microsoft for creating client-side web parts and extensions for SharePoint Online and SharePoint 2019. It is based on modern web technologies like JavaScript, TypeScript, and React, providing a rich and responsive user experience. Question 2: What are the key advantages of using SPFx for SharePoint development? Answer: SPFx offers several advantages, such as: Responsive and mobile-ready web parts and extensions. Seamless integration with SharePoint data and services. Support for modern web development practices and tools. Easy deployment and hosting options. Enhanced security and isolation through the SharePoint app model. Question 3: Can you explain ...

Interview Questions of SPFx SharePoint

SPFx Interview Questions and Scenarios SPFx Interview Questions and Scenarios By Vishal Thakur What is SPFx? The SharePoint Framework (SPFx) is a web part model that provides full support for client-side SharePoint development. It integrates seamlessly with SharePoint data and extends Microsoft Teams. SPFx allows developers to use modern web technologies and tools in their preferred development environment to build responsive and mobile-ready experiences. Scenario-Based Questions Scenario 1: External API Integration Scenario: Your team is developing an SPFx web part that needs to retrieve data from an external API and display it on a SharePoint site. The API requires authentication using OAuth 2.0. The web part should also allow users to refresh the data manually. Question: How woul...