Forum Discussion
How to add a counter to a SPFX app?
I would do it at the time that you do the query to fill ISPList[] . Are you using REST to get the events? If so, you can add $top to the query (and also do the sort at that point).
If not, you can do a for loop, instead of foreach.
for (var i = 0; i < COUNTER; i++) {
console.log(items[i].EventDate);
}Thanks!!
I am getting closer!
I was thinking that if I can use orderby = EventDate asc to sort the list, it would be possible to filter by EventDate so I can eliminate the if-sat to get the comming events only, so I tried this:
private _getListData(): Promise<ISPLists> {
let toDay = moment().format("L");
return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/lists/GetByTitle('${this.properties.calendarName}')/Items?$filter=EventDate ge datetime'" + toDay + "'$orderby= EventDate asc`, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();
});
}
But it seems that I am doing it wrong because nothing get filtered, I am getting all the events (both the old ones and the comming ones).
How should I use the filter?
Best regards
Americo
- cprotheroJun 14, 2018Iron Contributor
I have a very similar query. I have to use .toISOString();
$filter=EventDate ge datetime''' + today.toISOString() + "'&$orderby=EventDate&$top=10
Otherwise seems good. You can put that whole URL directly into a browser window to help tweak and see more specific error messages.