About
One common development scenario we as developers regularly implement is displaying SharePoint data into a tabular format with various functionality like sort, search, formatting etc. The most-used option was Bootstrap table and now with SPFx development, we can also show the list data on frontend webpart using react-bootstrap-table2.
Now react-bootstrap-table2 is available on NPM module, so it is also known as react-bootstrap-table-next.
In this article, we will see how to create a client Web Part, using SharePoint Framework and React JS that displays SharePoint List data into react-bootstrap-table. We will use PNP method to get list data.
First things first, let’s have a look into SharePoint List schema, from which we will pull the data. I have created a SharePoint list calling employee details with few dummy records.

Let’s start with our solution
Open node command prompt and create SPFx solution for web part using yeomen generator. Select React as a framework. Below is screen shot of my solution.
yo @microsoft/sharepoint

To verify if everything is okay with the solution, use gulp build command.

Add Pre-requisite
- To add react-bootstrap-table-next to solution, run the below command
npm install react-bootstrap-table-next –save
- Add @pnp/sp to solution, using the below command
npm install @pnp/sp
- Open the solution in VS code using command
code .
Our solution folder for webpart will look like the below image:

Now let’s start with coding part,
Open the file DataIntoBsTable.tsx file and add below import statements
- //Import related to react-bootstrap-table-next
- import BootstrapTable from 'react-bootstrap-table-next';
- //Import from @pnp/sp
- import { sp } from "@pnp/sp";
- import "@pnp/sp/webs";
- import "@pnp/sp/lists/web";
- import "@pnp/sp/items/list";
In Render function add the below code to load the css file:
- let cssURL = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css";
- SPComponentLoader.loadCss(cssURL);
Create table schema
- const empTablecolumns = [
- {
- dataField: "EmployeeName",
- text: "Employee Name",
- headerStyle : {backgroundColor: '#81c784'},
- sort : true
- },
- {
- dataField: "MobileNumber",
- text: "Mobile Number"
- },
- {
- dataField: "Departments",
- text: "Departments"
- },
- {
- dataField: "JoiningDate",
- text: "Joining Date"
- }];
Important points to take care of while deciding column Header:
- dataField :It will be same like column name in list item response
- text : It will be a name to show in the Table
- headerStyle : to added any colour (in this I have added header color to employee name column)
- sort : true (Ascending and Descending attributes).
There are various attributes like formatting, row based event and many more options available.
Code to get List Items and bind to table
Add a new interface to get list items
- export interface IShowEmployeeStates{
- employeeList :any[]
- }
Add Function to get all the list Items
- public getEmployeeDetails = () =>{
- sp.web.lists.getByTitle("EmployeeDetails").items.getAll().
- then((results : any)=>{
- this.setState({
- employeeList:results
- });
- });
- }





vemuriPosted Aug 26, 2021, 5:27 PM
Nice article. I would like to filter the initial array and assign this to bootstrap datafile. how to acheive this dynamic binding
Krishna AgrawalPosted Nov 9, 2020, 2:20 AM
Hi Vikas, Nice article..Well explained...I have a query like how can we display values of people picker field using this? Since we are getting Id of the people field in the response. Thanks
Amit KPosted Aug 28, 2020, 4:00 AM
Excellent tutorial...just want to know if there are more than 15 columns how we can set the width and implement a horizontal scroll?
anurag sainiPosted May 13, 2020, 12:37 AM
Keep posted such content so that others can grow as well.
anurag sainiPosted May 13, 2020, 12:36 AM
Very well explained. thanks for the informative content.