![]()
Create list in SharePoint Online using SPFx โ in this article, we will learn about how to create a list in SharePoint Online using the SPFx (SharePoint Framework).
Key-Highlights: Create list in SharePoint Online using SPFx
- Project Scaffolding process
- Install the PnP JS Module
- Add custom list to SharePoint Online method (function)
- Description โ add a custom list to SharePoint Online method (function)
- CreateListUsingSpfxWebPart.ts file entire code
- Verify the web part from the SharePoint Online page
Project Scaffolding process: Create list in SharePoint Online using SPFx
Create a Project folder name as โCreate List Using SPFxโ using the below command:
C:\Temp\SPFx>md "Create List Using SPFx"
Navigate to the newly created folder.
C:\Temp\SPFx>cd "Create List Using SPFx" C:\Temp\SPFx\Create List Using SPFx>
Now, run the yeoman SharePoint Generator command โ yo @microsoft/sharepoint
C:\Temp\SPFx\Create List Using SPFx>yo @microsoft/sharepoint
Hit enter, then enter the parameters when it asked as below:
Letโs create a new SharePoint solution.
? What is your solution name? create-list-using-sp-fx
? Which baseline packages do you want to target for your component(s)? SharePoint Online only (latest)
? Where do you want to place the files? Use the current folder
Found npm version 6.14.7
? Do you want to allow the tenant admin the choice of being able to deploy the solution to all sites immediately without
running any feature deployment or adding apps in sites? No
? Will the components in the solution require permissions to access web APIs that are unique and not shared with other componentsย in the tenant? No
? Which type of client-side component to create? WebPart
Add new Web part to solution create-list-using-sp-fx.
? What is your Web part name? create-list-using-spfx
? What is your Web part description? create-list-using-spfx description
? Which framework would you like to use? (Use arrow keys)
> No JavaScript framework
React
Knockout
Note:
- The above highlighted bold is the passed as input parameters.
Now, the project scaffolding process will start, this will take some time to complete, so have a little patience. ๐

Run gulp build command to check project scaffolding is completed successfully.

Type โcode .โ (without quotation) in the command prompt (node.js) to open the project in visual studio.
Install the PnP JS Module: Create list in SharePoint Online using SPFx framework
Run the below command to install the PnP JS module.
npm install sp-pnp-js --save
This is how the PnP JS has been loaded to the project. We can refer to it in the project by using the below code:
import { Web } from "sp-pnp-js";
Add custom list to SharePoint Online method (function): Create list in SharePoint Online using SPFx framework
Below is the main ts file to create the list in SharePoint Online using the SPFx framework:

Below is the main function to create the list in SharePoint Online using the SPFx framework:
privateย CreateListInSPOUsinPnPSPFx():ย voidย
ย ย ย ย {ย ย
ย ย ย ย ย ย ย ย letย myWebย =ย newย Web(this.context.pageContext.web.absoluteUrl);ย ย
ย ย ย ย ย ย ย ย //letย mySPFxListTitleย =ย "CustomList_using_SPFx_Framework";ย
ย ย ย ย ย ย ย ย letย mySPFxListTitleย =ย document.getElementById('listTitle')["value"];ย ย
ย ย ย ย ย ย ย ย letย mySPFxListDescriptionย =ย "Customย listย createdย usingย theย SPFxย Framework";ย ย
ย ย ย ย ย ย ย ย letย listTemplateIDย =ย 100;ย ย
ย ย ย ย ย ย ย ย letย boolEnableCTย =ย false;ย ย
ย ย ย ย ย ย ย ย myWeb.lists.add(mySPFxListTitle,ย mySPFxListDescription,ย listTemplateID,ย boolEnableCT).then(function(splist)
ย ย ย ย ย ย ย ย {ย ย
ย ย ย ย ย ย ย ย ย ย ย ย document.getElementById("ListCreationStatusInSPOnlineUsingSPFx").innerHTMLย +=ย `Theย SPOย newย listย `ย +ย mySPFxListTitleย +ย `ย hasย beenย createdย successfullyย usingย SPFxย Framework.`;ย ย
ย ย ย ย ย ย ย ย });ย ย
ย ย ย ย }ย ย
Description โ Add custom list to SharePoint Online method (Create list in SharePoint Online using SPFx framework)
The explanation of the above codes is as below:
let myWeb = new Web(this.context.pageContext.web.absoluteUrl);
Using this above line of code, the web part gets connected with the current SharePoint site (where the web part is deployed or hosted).
The below list of lines just takes the list creation input like the title of the list, description of the list, template id of the list, whether the list content type is enabled or not (boolean), etc.
letย mySPFxListTitleย =ย document.getElementById('listTitle')["value"];
ย ย ย ย ย ย ย ย letย mySPFxListDescriptionย =ย "Customย listย createdย usingย theย SPFxย Framework";
ย ย ย ย ย ย ย ย letย listTemplateIDย =ย 100;
ย ย ย ย ย ย ย ย letย boolEnableCTย =ย false;
myWeb.lists.add(mySPFxListTitle,ย mySPFxListDescription,ย listTemplateID,ย boolEnableCT).then(function(splist)
ย ย ย ย ย ย ย ย {
ย ย ย ย ย ย ย ย ย ย ย ย document.getElementById("ListCreationStatusInSPOnlineUsingSPFx").innerHTMLย +=ย `Theย SPOย newย listย `ย +ย mySPFxListTitleย +ย `ย hasย beenย createdย successfullyย usingย SPFxย Framework.`;
ย ย ย ย ย ย ย ย });
- Whatever the programming language you may opt for but the logic or way of passing the parameters to the inbuilt myWeb.lists.add() method is same.
CreateListUsingSpfxWebPart.ts file entire code (Create list in SharePoint Online using SPFx framework)
This is the main web part file where the code is located.
importย {ย ย
ย ย ย ย Webย ย
}ย fromย "sp-pnp-js";ย ย
importย {ย ย
ย ย ย ย Versionย ย
}ย fromย '@microsoft/sp-core-library';ย ย
importย {ย ย
ย ย ย ย BaseClientSideWebPart,ย ย
ย ย ย ย IPropertyPaneConfiguration,ย ย
ย ย ย ย PropertyPaneTextFieldย ย
}ย fromย '@microsoft/sp-webpart-base';ย ย
importย stylesย fromย './CreateListUsingSpfxWebPart.module.scss';ย ย
importย *ย asย stringsย fromย 'CreateListUsingSpfxWebPartStrings';ย ย
importย {ย escapeย }ย fromย '@microsoft/sp-lodash-subset';
exportย interfaceย ICreateListUsingSpfxWebPartProps
{
ย ย description:ย string;
}
exportย defaultย classย CreateListUsingSpfxWebPartย extendsย BaseClientSideWebPartย <ย ICreateListUsingSpfxWebPartPropsย >
ย {ย ย
ย ย ย ย publicย render():ย void
ย ย ย ย {ย ย
ย ย ย ย ย ย ย ย this.domElement.innerHTMLย =ย `
<divย class="${styles.createListUsingSpfx}">ย ย
<divย class="${styles.container}">ย ย
<divย class="ms-Grid-rowย ms-bgColor-themeDarkย ms-fontColor-whiteย ${styles.row}">ย ย
<divย class="ms-Grid-colย ms-u-lg10ย ms-u-xl8ย ms-u-xlPush2ย ms-u-lgPush1">ย ย
<spanย class="ms-font-xlย ms-fontColor-white"ย style="font-size:28px">Welcomeย toย SPFxย learningย (createย listย usingย PnPย JSย library)</span>ย ย
<pย class="ms-font-lย ms-fontColor-white"ย style="text-align:ย left">Demoย :ย Createย SharePointย Listย inย SPOย usingย SPFx</p>ย ย
</div>ย ย
</div>ย ย
<divย class="ms-Grid-rowย ms-bgColor-themeDarkย ms-fontColor-whiteย ${styles.row}">ย ย
<divย data-role="main"ย class="ui-content">ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย <divย >ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย <inputย id="listTitle"ย ย placeholder="Listย Name"/>ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย <buttonย id="createNewCustomListToSPO"ย ย type="submit"ย >Createย List</button>ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย </div>ย ย ย ย
ย ย ย ย ย ย ย ย ย ย ย </div>ย
<br>ย ย
<divย id="ListCreationStatusInSPOnlineUsingSPFx"ย />ย ย
</div>ย ย
</div>ย ย
</div>`;ย ย
ย ย ย ย ย ย ย ย this.AddEventListeners();ย ย
ย ย ย ย }ย ย
ย ย ย ย privateย CreateListInSPOUsinPnPSPFx():ย voidย
ย ย ย ย {ย ย
ย ย ย ย ย ย ย ย letย myWebย =ย newย Web(this.context.pageContext.web.absoluteUrl);ย ย
ย ย ย ย ย ย ย ย //letย mySPFxListTitleย =ย "CustomList_using_SPFx_Framework";ย
ย ย ย ย ย ย ย ย letย mySPFxListTitleย =ย document.getElementById('listTitle')["value"];ย ย
ย ย ย ย ย ย ย ย letย mySPFxListDescriptionย =ย "Customย listย createdย usingย theย SPFxย Framework";ย ย
ย ย ย ย ย ย ย ย letย listTemplateIDย =ย 100;ย ย
ย ย ย ย ย ย ย ย letย boolEnableCTย =ย false;ย ย
ย ย ย ย ย ย ย ย myWeb.lists.add(mySPFxListTitle,ย mySPFxListDescription,ย listTemplateID,ย boolEnableCT).then(function(splist)
ย ย ย ย ย ย ย ย {ย ย
ย ย ย ย ย ย ย ย ย ย ย ย document.getElementById("ListCreationStatusInSPOnlineUsingSPFx").innerHTMLย +=ย `Theย SPOย newย listย `ย +ย mySPFxListTitleย +ย `ย hasย beenย createdย successfullyย usingย SPFxย Framework.`;ย ย
ย ย ย ย ย ย ย ย });ย ย
ย ย ย ย }ย ย
ย ย ย ย privateย AddEventListeners()ย :ย void
ย ย ย ย {ย ย ย ย
ย ย ย ย ย ย
ย ย ย ย ย document.getElementById('createNewCustomListToSPO').addEventListener('click',()=>this.CreateListInSPOUsinPnPSPFx());ย ย ย ย
ย ย ย ย ย ย ย ย ย
ย ย ย ย }ย ย ย
ย ย ย ย protectedย getย dataVersion():ย Versionย {ย ย
ย ย ย ย ย ย ย ย returnย Version.parse('1.0');ย ย
ย ย ย ย }ย ย
ย ย ย ย protectedย getPropertyPaneConfiguration():ย IPropertyPaneConfigurationย {ย ย
ย ย ย ย ย ย ย ย returnย {ย ย
ย ย ย ย ย ย ย ย ย ย ย ย pages:ย [{ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย header:ย {ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย description:ย strings.PropertyPaneDescriptionย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย },ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย groups:ย [{ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย groupName:ย strings.BasicGroupName,ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย groupFields:ย [ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย PropertyPaneTextField('description',ย {ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย label:ย strings.DescriptionFieldLabelย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย })ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ]ย ย
ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย }]ย ย
ย ย ย ย ย ย ย ย ย ย ย ย }]ย ย
ย ย ย ย ย ย ย ย };ย ย
ย ย ย ย }ย ย
}
Verify the web part from the SharePoint Online page: Create list in SharePoint Online using the SPFx framework
Run the gulp serve command from the node.js command prompt and add this web part to SharePoint Online like below:
We need to add the web part to this page โ globalsharepoint2020.sharepoint.com/_layouts/15/workbench.aspx
Enter the list name in the list name textbox, then click on the โCreate Listโ button.

Output โ the below-highlighted list just got created thru the code.

Summary: Create list in SharePoint Online using SPFx framework
Thus, in this article, we have learned about how to create a list in SharePoint Online using the SPFx (SharePoint Framework) and the PnP JS library.
See Also: SPFx Framework Tutorial in SharePoint Online
You may also like the below SharePoint SPFx articles:
- SharePoint Online: Develop custom search web part using PnP JS and SharePoint Framework(SPFx)
- SharePoint Online: Use theme color in SharePoint SPFx framework web part
- SharePoint Online: CRUD operations using SPFx ReactJS framework
- SharePoint Online: CRUD operations using SPFx no javascript framework
- Develop your first hello world web part in sharepoint framework (SPFx)
- Understanding solution structure in SharePoint framework (SPFx)
- Create custom property in SharePoint Framework โ SPFx web part pane
- Get list items from SharePoint using SPFx framework(No Javascript Framework)
- Custom search result page in SharePoint Online โ SPFx PnP Modern Search solution
- Build your first SharePoint client-side web part (Hello World part 1)
ย
About Post Author
Discover more from Global SharePoint
Subscribe to get the latest posts sent to your email.
1 comments on โCreate List in SharePoint Online using SPFx (SharePoint Framework)โ