0.1.3 • Published 2 years ago

@spflow/grid v0.1.3

Weekly downloads
84
License
MIT
Repository
github
Last release
2 years ago

SPFlow Grid for SharePoint

Reusable declarative grid component for SharePoint List views applications.

The component is based on Fluent UI (former Office UI Fabric).

Supported platforms

  • SharePoint Online
  • SharePoint On-Prem (2019, 2016, 2013)

Main features

  • Declarative settings for most use-cases scenarios
    • List data source
    • OData, REST API projection (select, filter, top, expand, orderBy)
    • Columns model
  • Custom cell renderers
  • Embed and custom commands
  • Data enrichment
  • Columns runtime sorting
  • Grid columns customizable filter pane
  • True pagination
  • Export to Excel

Install

npm i @spflow/grid

Usage sample

import * as React from 'react';
import { GridView } from '@spflow/grid';

export const Component = (): JSX.Element => {

  return (
    <GridView
      listUri='_catalogs/masterpage'
      select='Id,Title,Editor/Title'
      expand='Editor'
      columns={[
        {
          key: 'Id',
          fieldName: 'Id',
          name: 'ID',
          minWidth: 40,
          maxWidth: 50
        },
        {
          key: 'Title',
          fieldName: 'Title',
          name: 'Title',
          minWidth: 150,
          maxWidth: 250
        },
        {
          key: 'Editor',
          fieldName: 'Editor/Title',
          name: 'Editor',
          minWidth: 150,
          maxWidth: 250
        }
      ]}
      commands={[
        { key: 'view' }
      ]}
      top={10}
    />
  );

};

Grid API Reference

Required properties

ParameterDescription
listUriSharePoint List URL, e.g. 'Lists/MyList', should not contain web relative URL
selectOData (REST API) field names to select and use in the grid, not necessarily should be presented in a view explicitly

List API query properties (optional)

ParameterDescription
filterOData (REST API) filter condition applied to grid view
expandOData (REST API) expand fields, e.g. a lookup field 'Editor' if 'Editor/Id,Editor/Title' is considered in select property
topOData (REST API) top number defines view page size
orderByOData (REST API) fields default sort constructor array, each object is { fieldName: string; ascending: boolean; }

Grid properties (optional)

ParameterDescription
titleView title, a text shown above grid component
showBackButtonIf true view back button is rendered
columnsColumns configuration model (see more below)
commandsCommand bar actions configuration model (see more below)
filterFieldsEnabled grid filters configuration model (see more below)
rendersCustom cell renderers collection object
onSelectionChangedGrid items selection change callback handler
reloadKeyWhen a new unique key is provided externally, grid refreshes itself
viewModeWhen true default edit commands are blocked
selectionModeFluentUI selection mode property bypass
enrichDataOnPageLoadData enrichment callback, can be used to request additional data after a page items loaded, e.g. request external API or something which is not possible to retrieve using standard OData approach
commandsCustomRulesCustom rules callback collection, the rules can be used in Commands enable option, allows action enable based on metadata or external conditions
emptyGridMessageMessage shown when no items are in the grid view response
viewStorageKeyUnique string used for local storage to persist grid state (applied filters, sort conditions, etc.) so these can be kept after a page reload

Columns model properties

Extends FluentUI IColumn interface.

ParameterDescription
fieldNameOData field name, maps API data and default view cell renderer, e.g. Title or Lookup/Title (required)
typeType renderers helper, allows rendering Boolean, Date, DateTime values without providing a custom renterer but reusing default embed helpers
disableSortIf true sorting by a column is disabled, must to applied for column types which do not support sorting (e.g. Note field)

Other properties are a bypass of FluentUI Details List IColumn interface, see more.

The required by FluentUI columns are: key, name, minWidth.

Filters model properties

ParameterDescription
labelFilter label
fieldNameOData (REST API) field name, some cases might also require adding corresponding expand and select values to the grid properties
fieldTypeCan be one of the following: 'string', 'number', 'date', 'lookup', 'boolean'
dictionaryA dictionary of values which can be selected in the filter, can be used together with 'string', 'number' and 'boolean' fieldTypes
lookupPropsLookup configuration object, is relevant only with 'lookup' fieldType, lookup props allows not only define which list to use, but also provide some options

Commands model properties

Extends FluentUI ICommandBarItemProps interface.

ParameterDescription
enableRuleString of |-separated rules which define if an action is enabled for the selected item(s) in a view
showRuleSame as enableRule but hides an action button instead of disabling
onClickHandlerAction handler

There are some predefined actions, such as 'add', 'copy', 'view', 'edit', 'delete'. These commands can be added in a simplified way by a shortcut declaration, e.g. { key: 'view' } will add the default view action button.

A sample of a rule:

enableRule: `onSingleSelection|permissions:${PermissionKind.EditListItems}|custom:myRule`

To operate with permissions, EffectiveBasePermissions property should be selected along with other fields in a grid definition.

Enable/show rules

Rules are declarative, within default rules are the following:

RuleDescription
onSingleSelectionWhen only a single item is selected in a view
onMultipleSelectionWhen multiple items are selected in a view
onAnySelectionWhen one or many items are selected in a view
permissions:[PermissionKind]Based on permissions where [PermissionKind] is permissions bit (see more)
custom:[CustomRule]Where [CustomRule] is a callback rule defined in commandsCustomRules
0.1.3

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.41

3 years ago

0.0.40

3 years ago

0.0.39

3 years ago

0.0.38

3 years ago

0.0.37

3 years ago

0.0.36

3 years ago

0.0.35

3 years ago

0.0.34

3 years ago

0.0.33

3 years ago

0.0.32

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.28

3 years ago

0.0.27

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago