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. {  

  3. return {      

  4. pages: [        

  5. {          

  6. header: {            

  7. description: "SPFx Properties Page 1"         

  8. },          

  9. groups: [            

  10. {              

  11. groupName: "Dynamic Properties - Page 1",              

  12. groupFields:   

  13. this.dynamicProps                          

  14. }          

  15. ]        

  16. },        

  17. {          

  18. header: {            

  19. description: "SPFx Properties Page 2"         

  20. },          

  21. groups: [            

  22. {              

  23. groupName: "Dynamic Properties - Page 2",              

  24. groupFields:                 

  25. []                          

  26. }          

  27. ]        

  28. },        

  29. {          

  30. header: {            

  31. description: "SPFx Properties Page 3"         

  32. },          

  33. groups: [            

  34. {              

  35. groupName: "Dynamic Properties - Page 3",              

  36. groupFields:                 

  37. []                          

  38. }         

  39.  ]        

  40. }      

  41. ],  

  42. //currentPage: 3,     

  43. loadingIndicatorDelayTime: 5,      

  44. showLoadingIndicator: this.loadIndicator    };  }  

  45. protected onPropertyPaneConfigurationStart(): void {    

  46. var self = this;  

  47. var xmlhttp = new XMLHttpRequest();        

  48. xmlhttp.onreadystatechange = function () {  

  49. if (xmlhttp.readyState == XMLHttpRequest.DONE) {  

  50. if (xmlhttp.status == 200) {  

  51. var data = JSON.parse(xmlhttp.responseText);  

  52. if (data != null) {                      

  53. self.dynamicProps = [];                        

  54. data.d.results.forEach(function(item){  

  55. / /self.dynamicProps.push({key: item.ID, text: item.Title});                       

  56. self.dynamicProps.push(                          

  57. PropertyPaneCheckbox(item.ID,                          

  58. {                            

  59. text:item.Title                          

  60. })                           

  61. );                      

  62. });                      

  63. self.loadIndicator= false;                      

  64. self.context.propertyPane.refresh();                     

  65. }                

  66. else

  67. if (xmlhttp.status == 400) {                    

  68. console.log('There was an error 400');                 

  69. else 

  70. {                    

  71. console.log('something else other than 200 was returned');                

  72. }                            

  73. }        

  74. };  

  75. var inputUrl = "https://nakkeerann.sharepoint.com/sites/spfx/_api/web/lists/getByTitle('TestList')/items";        

  76. xmlhttp.open("GET", inputUrl, true);        

  77. xmlhttp.setRequestHeader("Accept","application/json; odata=verbose");        

  78. xmlhttp.send();          

  79. }  

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.

Recent Posts

See All