Hi,
I am working in a SP framework application that read, group and filter data from a list.
To do that I have a method in the app that get called from an onclick eventhandler.
This method contains just a switch to check what other method needs to be called. It looks like this:
private _handleRequest(request: string): void {
switch (request) {
case 'Customer':
case 'Sales Manager':
this.groupHandler(request);
break;
case 'Agreement Ended':
this.getEnded();
break;
case 'Last Price Adjustment':
this.getPassed();
break;
default:
break;
}
}
The groupHandler method send a request to Sharepoint that fetchs all the data and then send the data to a ListView component which render it on the screen:
private groupHandler(group: string): void {
group = group.replace(/ +/g, "");
this.setState({
groupByFields: [{
name: group,
order: GroupOrder.ascending
}]
});
}
}
The getEnded and getPassed are almost similar, fetch data from sharepoint and filter the result before it is sended to the ListView component.
Each method update the state:
private getEnded(): void {
this.props.provider.getEnded().then((listItems: IList[]) => {
this.setState({
listItems: listItems
});
});
}
private getPassed(): void {
this.props.provider.getPassed().then((listItems: IList[]) => {
this.setState({
listItems: listItems
});
});
}
ans it is initialize like this:
export interface IListState {
listItems: IList[];
}
export default class AgreementDatabase extends React.Component<IAgreementDatabaseProps, IListState> {
constructor(props: IAgreementDatabaseProps) {
super(props);
this.state = {
listItems: []
};
this.groupHandler = this.groupHandler.bind(this);
}
No the problem is, when I run the app and click on a link that call the groupHandler method the list get grouped without problem. The problem arise when, with the list grouped, I click on a link that call getEnded or getPassed method. In that case the list doesn’t reload before filtering the result. What I get is a grouped list with filtered results.
I post some images to better understanding.
How can I reset the state so every time I click on a button the app fetch the original state / values before applying filtering or grouping?
Best regards
Americo