SPFx Property Pane Configuration Options

Introduction

In this article, let us see the options available for the configuration of SharePoint Webpart Properties Pane.

The sample explained here is in continuation of my previous post. In my previous post, I have explained how to render the SPFx web part properties pane based on list data asynchronously. 

IPropertyPaneConfiguration Interface
 
The SPFx web part properties pane implements the IPropertyPaneConfiguration interface available. So in the web part file code, by default getPropertyPaneConfiguration extends the IPropertyPaneConfiguration interface. This can be seen in my previous post as well. So far I have shown only the property configuration method returning the pages property.

The IPropertyPaneConfiguration interface contains the following properties. 

  • pages – pages denotes collection of pages (implements IPropertyPanePage[]). Each and every page in the IPropertyPanePage array contains the header and groups properties. The header is used for denoting the page name, and the groups will contain the collection of properties used in the properties pane.
  • currentPage – Current Page denotes the page number to be shown when the pane property is opened. (This seems to be not working as expected).
  • loadingIndicatorDelayTime – Loading indicator delay time denotes the number of milliseconds for delaying the loading indicator on the property pane before rendering.
  • showLoadingIndicator – It is a Boolean property used to decide whether the loading indicator is shown or not. 

Sample 

Let us try adding these properties in our sample here.

The below web part file contains the web part configuration method, which has three pages. The first page contains the dynamic properties to be loaded (explained in my previous article). The other two pages contain the groups with no properties.

Loading indicator is shown when the property pane loads. It is turned off, when the properties in the pane are loaded with data. This is very useful for loading the data using asynchronous calls. loadingIndicatorDelayTime property is used to decide delay time for showing the loading indicators. By default, delay time for loading indicator is 500 milliseconds. In the sample, I have given only 5 milliseconds. 

  1. protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {  
  2.   return {  
  3.     pages: [  
  4.       {  
  5.         header: {  
  6.           description: "SPFx Properties Page 1"  
  7.         },  
  8.         groups: [  
  9.           {  
  10.             groupName: "Dynamic Properties - Page 1",  
  11.             groupFields:   
  12.               this.dynamicProps                
  13.           }  
  14.         ]  
  15.       },  
  16.       {  
  17.         header: {  
  18.           description: "SPFx Properties Page 2"  
  19.         },  
  20.         groups: [  
  21.           {  
  22.             groupName: "Dynamic Properties - Page 2",  
  23.             groupFields:   
  24.               []                
  25.           }  
  26.         ]  
  27.       },  
  28.       {  
  29.         header: {  
  30.           description: "SPFx Properties Page 3"  
  31.         },  
  32.         groups: [  
  33.           {  
  34.             groupName: "Dynamic Properties - Page 3",  
  35.             groupFields:   
  36.               []                
  37.           }  
  38.         ]  
  39.       }  
  40.     ],  
  41.     //currentPage: 3,  
  42.     loadingIndicatorDelayTime: 5,  
  43.     showLoadingIndicator: this.loadIndicator  
  44.   };  
  45. }  
  46. protected onPropertyPaneConfigurationStart(): void {    
  47.   var self = this;  
  48.       var xmlhttp = new XMLHttpRequest();  
  49.       xmlhttp.onreadystatechange = function () {  
  50.           if (xmlhttp.readyState == XMLHttpRequest.DONE) {  
  51.               if (xmlhttp.status == 200) {  
  52.                   var data = JSON.parse(xmlhttp.responseText);  
  53.                   if (data != null) {  
  54.                     self.dynamicProps = [];  
  55.                       data.d.results.forEach(function(item){  
  56.                       //self.dynamicProps.push({key: item.ID, text: item.Title});  
  57.                       self.dynamicProps.push(    
  58.                       PropertyPaneCheckbox(item.ID,  
  59.                         {  
  60.                           text:item.Title  
  61.                         })     
  62.                       );  
  63.                     });  
  64.                     self.loadIndicator= false;  
  65.                     self.context.propertyPane.refresh();  
  66.                     
  67.                   }  
  68.               } else if (xmlhttp.status == 400) {  
  69.                   console.log('There was an error 400');  
  70.                     
  71.               } else {  
  72.                   console.log('something else other than 200 was returned');  
  73.               }                  
  74.           }  
  75.       };  
  76.   
  77.       var inputUrl = "https://nakkeerann.sharepoint.com/sites/spfx/_api/web/lists/getByTitle('TestList')/items";  
  78.       xmlhttp.open("GET", inputUrl, true);  
  79.       xmlhttp.setRequestHeader("Accept","application/json; odata=verbose");  
  80.       xmlhttp.send();          
  81. }   
The below snapshot shows the properties pane with loading image.
 
Summary
 
Thus, you have seen the SharePoint Framework Properties Pane methods and the properties with loading indicator.