This article provides a step-by-step introduction to configure Syncfusion JavaScript (Essential JS 2) library and build a simple SharePoint framework application in Visual Studio Code.
ej2-sharepoint
, open the command prompt from that directory, and install the required SharePoint client-side development tools with global flag.on Windows:
npm install -g yo gulp @microsoft/generator-sharepoint
on OSX / LINUX
sudo npm install -g yo gulp @microsoft/generator-sharepoint
The Yeoman SharePoint web part generator
@microsoft/generator-sharepoint
helps to create a SharePoint client-side project usingYeoman
tool.
yo @microsoft/sharepoint
Next, it will ask the specific information about the web part.
ej2-sharepoint
folder and install the required default dependencies.@syncfusion/ej2
npm package in the application using the following command line.npm install @syncfusion/ej2 --save
~/src/webparts/buttonComponent/ButtonComponentWebPart.ts
file.this.domElement.innerHTML
, and initialize the Syncfusion JavaScript Button in the render()
method of ButtonComponentWebPart
class.....
....
import styles from './ButtonComponentWebPart.module.scss';
import * as strings from 'ButtonComponentWebPartStrings';
// import Essential JS 2 Button
import { Button } from '@syncfusion/ej2-buttons';
// add Syncfusion Essential JS 2 style reference from node_modules
require('../../../node_modules/@syncfusion/ej2/fabric.css');
....
....
export default class ButtonComponentWebPart extends BaseClientSideWebPart<IButtonComponentWebPartProps> {
public render(): void {
this.domElement.innerHTML = `
<div class="${ styles.buttonComponent }">
....
....
<!--HTML button element, which is going to render as Essential JS 2 Button-->
<button id="normalbtn">Essential JS 2 Button</button>
</div>`;
// initialize button control
let button: Button = new Button();
// render initialized button
button.appendTo('#normalbtn');
}
....
....
}
gulp serve
Click the Add a new web part in column one
.
Select the ButtonComponent
web part.
Finally, the Syncfusion JavaScript Button control is rendered in the SharePoint Framework client-side web part.