I'm writing a web part to query data from SharePoint Online, the data returned is displayed using a DetailsList component, the problem I'm having is with queries that take a long time to return their results, the web part doesn't get refreshed and stays sitting on the page "empty":
For fast queries taking 1-2 seconds, the web part gets updated and display the results normally:
I also want to give a feedback to my users to show the web part is busy by using displayLoadingIndicator() but I can't get this to work.
Here it is my code (abbreviated for simplicity):
- NavigatorWebPart.ts
export default class NavigatorWebPart extends BaseClientSideWebPart<INavigatorWebPartProps> {
protected onInit(): Promise<void> {
this.context.statusRenderer.displayLoadingIndicator(this.domElement, "Querying items...");
return super.onInit();
}
public render(): void {
const element: React.ReactElement<INavigatorProps> = React.createElement(Navigator, {});
ReactDom.render(element, this.domElement);
}
- Navigator.tsx
let listItems : any[] = [];
const listColumns : IColumn[] = [... // shortened for brevity
export default class Navigator extends React.Component<INavigatorProps, IListMembers> {
constructor(props) {
super(props);
this.queryLists();
// this.context.statusRenderer.clearLoadingIndicator(this.domElement);
this.state = {
items : listItems,
columns : listColumns,
compactMode : false
};
}
public render(): JSX.Element {
const { items, columns, compactMode } = this.state;
return (
<div>
<div className='ms-SearchBoxSmall'>
<CommandBar
isSearchBoxVisible={ true }
items={ [] }
farItems={ this.listFarItems }
/>
</div>
<br />
<div>
<DetailsList
items={ items }
columns={ columns }
compact={ compactMode }
layoutMode={ DetailsListLayoutMode.justified }
selectionMode={ SelectionMode.none }
onColumnHeaderClick={ this._onColumnClick }
/>
</div>
</div>
);
}
public async queryLists() {
await sp.web.lists
.filter("Hidden eq false")
.expand('RootFolder')
.get()
.then( response => {
response.forEach( (item, index) => {
var newData = new Date(item.LastItemModifiedDate).toLocaleDateString() + ' ' + new Date(item.LastItemModifiedDate).toLocaleTimeString();
listItems.push({
"ID" : index,
"URL" : item.RootFolder.ServerRelativeUrl,
"Icon" : item.BaseTemplate,
"Title" : item.Title,
"Total" : item.ItemCount,
"Modified" : newData
});
});
});
}