Skip to main content

ListViewService

@spartanfx/react v1.2.2


@spartanfx/react / spfx / ListViewService

Class: ListViewService

A reusable service for loading SharePoint list metadata and items, supporting CAML queries, server-side search, paging, sorting, and filtering.

Designed for use in SPFx solutions with a React ListView component.

Deprecated​

DEPRECATED - This service is deprecated and will be removed in a future version.

Replacement: Use DataTable component with the useSharePointDataTable hook instead. DataTable provides the same functionality with a simpler, hooks-based API.

Example​

Migrating to useSharePointDataTable

// Before (ListViewService)
const listViewService = new ListViewService({ sp, listName: 'MyList' });
<ListView listViewService={listViewService} columns={columns} context={context} />

// After (useSharePointDataTable)
const dataTableProps = useSharePointDataTable({ sp, listName: 'MyList' });
<DataTable {...dataTableProps} columns={columns} />

Constructors​

Constructor​

new ListViewService(configuration): ListViewService;

Parameters​

configuration​

IListViewServiceConfig

Returns​

ListViewService

Methods​

forceRefresh()​

forceRefresh(): void;

Triggers a refresh event that components using this service can subscribe to.

Returns​

void


loadList()​

loadList(): Promise<IListInfo>;

Loads SharePoint list metadata such as title, ID, and base template.

Returns​

Promise<IListInfo>


loadListFields()​

loadListFields(): Promise<IFieldInfo[]>;

Retrieves all field definitions from the SharePoint list.

Returns​

Promise<IFieldInfo[]>


loadListItems()​

loadListItems(
columns?,
pageRef?,
rowLimit?,
filters?,
sortField?,
searchText?): Promise<any>;

Loads list items from SharePoint with CAML support, column projection, sorting, filtering, and pagination.

Parameters​

columns?​

string[]

Optional field internal names to include in the view.

pageRef?​

string

Optional paging token to retrieve next page of results.

rowLimit?​

number

Optional override for row limit per page.

filters?​

Key-value map of filter conditions.

sortField?​

any

Optional sorting definition { SortField: string, SortDir: 'Asc' | 'Desc' }.

searchText?​

string

Optional text query for server-side search.

Returns​

Promise<any>


offForceRefresh()​

offForceRefresh(callback): void;

Unsubscribes a callback from the force refresh event.

Parameters​

callback​

() => void

The callback to remove.

Returns​

void


onForceRefresh()​

onForceRefresh(callback): void;

Subscribes to the force refresh event.

Parameters​

callback​

() => void

Function to call when a refresh is triggered.

Returns​

void


getFieldInfo()​

static getFieldInfo(listFields, internalName): IFieldInfo;

Utility function to find a specific field definition by internal name.

Parameters​

listFields​

any[]

List of IFieldInfo objects.

internalName​

string

The internal name of the field.

Returns​

IFieldInfo

Properties​

PropertyTypeDescription
camlQuerystring-
inPlaceFilterItems(items) => any[]-
listNamestring-
spSPFI-