SharePoint Online Document Library Information Dynamically – React n Rest Api


I have come out with one requirement which can tell the number files in the document library. Regardless the number of document in the library. I have used React with rest api to get all the folder, and document type count with some ready made components on react. I would like others input to make it more optimize and speedy.

Web part takes document library name from the property name dynamically.

 

Code is already uploaded on Git Hub.

Resultant screen shot of our solution will be like below.

 

 

 

SP Document Library Information
SP Document Library Information

Step 1.  yo @microsoft/sharePoint
Step 2. Choose SharePoint Online only (latest)
Step 3. Use the current folder
Step 4. 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? (y/N) Choose y
Step 5. Select WebPart
Step 6.What is your Web part name?
Step 7 What is your Web part description?
Step 8. Which framework would you like to use? Chooe React
wait around 3 minutes npm to make necessary files………

Install Jquery and react-countup
i.e. npm install jquery –save Similary
npm install react-countup –save

Go to the component tsx file inside src – > webpart – > yourwebparname.tsx

Go to the interface your webpart calss is inheriting….. and update with below.

import { SPHttpClient } from ‘@microsoft/sp-http’;

export interface IWpDocumentLibInfoProps {
spHttpClient: SPHttpClient;
TotalItem:string;
TotalFolders:string;
TotalFiles:string;
description: string;
siteurl:string;
ItemStart:number;
ItemEnd:number;
LoopForList:number;
FileArray:Array<string>;
DocFiles:number;
XlsFiles:number;
PDFFiles:number;
P3Files:number;
Photos:number;
Drawing:number;
TextFiles:number;
MISCFiles:number;
DocumentLibraryName:string;
}

Now come back to tsx file and add the below function one by one.

import CountUp from ‘react-countup’;
import * as jquery from ‘jquery’;

1. Constructor

2. Add below code : It will run during initializing and bring the cound of the document library using rest.
componentDidMount() {
this._GetListTotalCount();
}

private _GetListTotalCount(): void {
var reactHandler = this;
var NewISiteUrl = this.props.siteurl;
var NewSiteUrl = NewISiteUrl.replace(“SitePages”, “”);
if (this.state.DocumentLibraryName==””){return;}
console.log(NewSiteUrl);
jquery.ajax({
url: `${NewSiteUrl}/_api/web/Lists/getbytitle(‘${this.state.DocumentLibraryName}’)/ItemCount`,
type: “GET”,
headers: { ‘Accept’: ‘application/json; odata=verbose;’ },
success: function (resultData) {
this.setState({ TotalItem: resultData.d.ItemCount })
var number = parseInt(this.state.TotalItem);
var LoopToQuery = number / 4000;
var LooingItemInt = Math.ceil(LoopToQuery)
this.setState({ LoopForList: LooingItemInt });
this.QueryFilesAndFoldersWrapper();
}.bind(this),
error: function (jqXHR, textStatus, errorThrown) {
}

});
}

3.Add this function QueryFilesAndFoldersWrapper # Code is already on the Git Hub

4.QueryITems in Loop because due to 5000 threshold limit we can query rest in chunks of 4999 records.

5. Add the render Method # from git hub.

We can change the Document Library Name from the Property Pane save and refresh.

 

#Kindly download the code and help me to make it more optimize and more usable for others.

#Happy sharing…..

 

 

Advertisements

Employee Directory with SPFX ReactJS Using SharePoint Search Rest Api – Modern Webpart


Employee directory is now become a tea spoon in SharePoint. By using Search with Rest Api and react we can easily integrate in our SharePoint Pages.  Another best advantage is we can re-use the react component as well as we can use it on the classic site template.

Screen shots are mentioned below and the Code is on the Git Hub.

This component can fetch the user profile and get the department of login user and query to Search People rest api.

 

blog_01

 

 

1. Open Powershell and write the command to Create a SharePoint Framework project. yo @microsoft/sharePoint.

SharePoint Framework - Npm Package Manager
SharePoint Framework – Npm Package Manager

2. Options and settings are in the screen shot. i.e. Choose webpart, name, framework as react to make reuseable component. It will take a while to complete all pre-requisit.

SharePoint Framework - Npm Package Manager
SharePoint Framework – Npm Package Manager

3. Install Jquery through npm install jquery –save command

4. Instal react-radio-group throug npm install react-radio-group –save command
5. Open the solution in the VS Code Editor by “code .”

6. Go to the src->components->EmployeeDirectory.tsx file add the code.
a. First we need to add more proerties in the IEmployeeDirectoryProps interface

b. Import Libraries for request, jquery, radio group to be available in the component

b. Import Libraries for request, jquery, radio group to be available in the component

c. Add Constructor

SPFX ES6 Constructor
SPFX ES6 Constructor

d. RequestSeach Method

e. Render Method

Render Methods
Render Methods

f. Adding CSS. Open src->components->EmployeeDirectory.module.css.ts and add the css.

–Happy Sharing………

Dynamic Filters in SharePoint Framework- React Component


Microsoft SharePoint framework with all its limitation, but the awesome framework for SP developer. Recently I encounter a bit different requirement on SharePoint framework. To filter data of SP List using react-Switch and textbox. The code is uploaded to the Git hub Link.

To Learn about reactJs and reactes6 use this Link – Learn React Js es6 Link

I used Sharepoint rest API and react-switch to filter data on the list.

Webpart

SharePoint Framework Switch Webpart

(1) Create project using yo @microsoft/SharePoint

(2) Create We part with react extension (by doing this it will create react as component)

(3) Pass SPHttpclient and Page URL as props to the component class.

(4) We will use Rest Call to List data

happy sharing…..

Office 365 New features: MyAnalytics – Trends and Your time investments


We office 365 with another intelligent feature with the name MyAnalytics which seems very impressive. It is free available with E5 subscription however for other we have to purchase.

MyAnalytics uses data from Office 365 to help people across your organization understand how they spend their time and discover opportunities to work smarter.

All data surfaced in MyAnalytics is private and available only to the end user.

The new “Trends” chart gives users a visual overview of how their work habits have changed over time. The “Your time investments” chart provides a network map that helps users visualize and prioritize their relationships.

 

Trends: find long-term trends in your work habits

Capture

Your time investments: visualize and strengthen your network

MyAnalytics now visualizes your network so that you can identify missing links, improve your relationships, and prioritize the time you spend with co-workers.

Capture.PNG

Additional Information – Portal Office