SPFX CRUD operation using no javascript SPHttpClient

Implemented Site URL:

 https://mercedessaga.sharepoint.com/sites/teja_dev/SitePages/SPFX-CRUD-operations.aspx

----------------------------------

Sp List URL: Developer Site - SoftwareCatalog - All Items (sharepoint.com)




SharePoint Output webpart design



















SPFX Code:

ISoftwareListitems.ts// which is an interface class

export interface ISoftwareListItem{
    Id:number;
    Title:string;
    SoftwareVendorstring;
    SoftwareDescriptionstring;
    SoftwareName:string;
    SoftwareVersionstring;
}

mainwebpartname.ts:


import { Version } from '@microsoft/sp-core-library';
import {
  IPropertyPaneConfiguration,
  PropertyPaneTextField,
  PropertyPaneCheckbox,
  PropertyPaneDropdown,
  PropertyPaneToggle,
  PropertyPaneSlider,
  PropertyPaneLink
from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import { escape } from '@microsoft/sp-lodash-subset';

import styles from './HelloWorldWebPart.module.scss';
import * as strings from 'HelloWorldWebPartStrings';
import MockHttpClient from './MockHttpClient';
import {
  SPHttpClient,
  SPHttpClientResponse
from '@microsoft/sp-http';
import {
  Environment,
  EnvironmentType
from '@microsoft/sp-core-library';
export interface IHelloWorldWebPartProps {
  descriptionstring;
  teststring;
  test1boolean;
  test2string;
  test3boolean;
}
export interface ISPLists {
  valueISPList[];
}
export interface ISPList {
  Titlestring;
  Idstring;
}
export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {

  private _getMockListData(): Promise<ISPLists> {
    return MockHttpClient.get()
      .then((dataISPList[]) => {
        var listDataISPLists = { value: data };
        return listData;
      }) as Promise<ISPLists>;
  }
  private _getListData(): Promise<ISPLists> {
    return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/lists?$filter=Hidden eq false`SPHttpClient.configurations.v1)
      .then((responseSPHttpClientResponse=> {
        return response.json();
      });
  }
  private _renderList(itemsISPList[]): void {
    let htmlstring = '';
    items.forEach((itemISPList=> {
      html += `<ul class="${styles.list}">
      <li class="${styles.listItem}">
        <span class="ms-font-l">${item.Title}</span>
      </li>
    </ul>`;
    });
  
    const listContainerElement = this.domElement.querySelector('#spListContainer');
    listContainer.innerHTML = html;
  }
  private _renderListAsync(): void {
    // Local environment
    if (Environment.type === EnvironmentType.Local) {
      this._getMockListData().then((response=> {
        this._renderList(response.value);
      });
    }
    else if (Environment.type == EnvironmentType.SharePoint ||
             Environment.type == EnvironmentType.ClassicSharePoint) {
      this._getListData()
        .then((response=> {
          this._renderList(response.value);
        });
    }
  }
  public render(): void {
    this.domElement.innerHTML = `
      <div class="${styles.helloWorld}">
        <div class="${styles.container}">
          <div class="${styles.row}">
            <div class="${styles.column}">
              <span class="${styles.title}">Welcome to SharePoint!</span>
              <p class="${styles.subTitle}">Customize SharePoint experiences using Web Parts.</p>
              <p class="${styles.description}">${escape(this.properties.description)}</p>
              <p class="${styles.description}">${escape(this.properties.test)}</p>
<p class="${styles.description}">${this.properties.test1}</p>
<p class="${styles.description}">${escape(this.properties.test2)}</p>
<p class="${styles.description}">${this.properties.test3}</p>
<p class="${ styles.description }">Loading from ${escape(this.context.pageContext.web.title)}</p>
              <a href="https://#" class="${styles.button}">
                <span class="${styles.label}">Learn more</span>
              </a>
            </div>
          </div>
          <div id="spListContainer" />
        </div>
      </div>`;
      this._renderListAsync();
  }

  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
                }),
                PropertyPaneTextField('test', {
                  label: 'Multi-line Text Field',
                  multiline: true
                }),
                PropertyPaneCheckbox('test1', {
                  text: 'Checkbox'
                }),
                PropertyPaneDropdown('test2', {
                  label: 'Dropdown',
                  options: [
                    { key: '1'text: 'One' },
                    { key: '2'text: 'Two' },
                    { key: '3'text: 'Three' },
                    { key: '4'text: 'Four' }
                  ]
                }),
                PropertyPaneToggle('test3', {
                  label: 'Toggle',
                  onText: 'On',
                  offText: 'Off'
                })
              ]
            }
          ]
        }
      ]
    };
  }
}

Comments

Popular posts from this blog

Powerapps overcome 2000 item limit from any datasource

PowerApps multiselect cascading dropdown and save an item to SharePoint List

Multi select cascading dropdown in Power Apps