0

I am trying below code to fetch list items from SharePoint and displaying in table format using REST API up to some point I have wrote the below code. I am unable to figure out how the items will be fetched or how to select columns from list items to display it in table (Suppose I do have Name, Email, Phone and ID on list items):

$.ajax({ 
    url: `${this.props.siteUrl}/_api/Web/Lists/GetByTitle('App_Name')/items`, 
       type: "GET", 
       headers:{'Accept': 'application/json; odata=verbose;'}, 
       success: function(resultData) {          
         reactHandler.setState({ 
           items: resultData.d.results 
         }); 
       }, 
       error : function(jqXHR, textStatus, errorThrown) { 
       } 
   }); 

For displaying it in table format I am using react-table-component which has rows and columns value in it.

1
  • What I am trying to do how to put values in rows and columns property of react-data-table-component Commented Nov 13, 2020 at 6:42

2 Answers 2

1

You can use $select in SharePoint REST API to select particular columns from SharePoint list. You need to use internal name of column in REST API. You can get the internal name of your columns by following this article: How to find the Internal name of columns in SharePoint Online?

You can use REST endpoint like:

/_api/Web/Lists/GetByTitle('App_Name')/items?$select=ID,Title,Name,Email,Phone
1
  • No, not like that I mean I have to represent it in a table format and for that I am using react-data-table-component. In that there are properties rows and columns so how to put the Sharepoint items in rows and columns of react-data-table Commented Nov 12, 2020 at 10:50
1

@Dhanjay Bhardwaj,

If you're developing an SPFx React app (webpart or extension), I suggest you use SPHttpClient or PnPJS to fetch items from SharePoint list.

Compare to $.ajax, the above helper classes execute REST API requests against SharePoint. It adds default headers, manages the digest needed for writes.

You can have a look below tutorials:

1
  • If I change from ajax to SP now I have to change it in all of my files. cause using different methods in different file will take time to understand the code Commented Nov 12, 2020 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.