Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I persist web part state from inside a client web part content page?

I have just set up and created by first ever SharePoint development effort: a project for a web part, to be hosted in a SharePoint Online instance (my Office 365 trial).

I have figured out how to use the List API to pull the content I am supposed to present, being a rotating list of banner images, but I have one remaining concern. I would like to keep track of where in the list I am, and when last I changed images. Another question of mine answers this quite nicely if I go with local storage, but is there any SharePoint REST or JSOM API I can use to persist this state in the SharePoint service?

like image 952
ProfK Avatar asked Dec 09 '14 11:12

ProfK


People also ask

Where can SharePoint framework client side web parts be used?

Client-side web parts can be used to deploy single page apps (SPAs) in SharePoint Online. For more information about using web parts as SPAs, see Using single part app pages in SharePoint Online. Client-side web parts can be used to implement tabs in Microsoft Teams.

Which type of web part should you use ensure that access to the exclusive to the web part?

Using the unique domain allows to ensure, that only web parts from the particular SharePoint Framework solution can obtain an access token for the isolated set of permissions.

What is difference between client side and server side in SharePoint?

Server-side programming is writing code that runs on the server, using languages supported by the server such as C#, VB.NET. On the other hand Client-side programming is writing code that will run on the client (user's browser), and is done in languages that can be executed by the browser, such as JavaScript.


1 Answers

I like the local storage answer, but you could also write the state information to another SharePoint list.

Keep track of the information on a per user basis (probably against their user ID, since they'll likely be authenticated) and have send an AJAX request or a JSOM request without any visible callback behavior each time the viewer's state changes (maybe even use a web worker for users that support them).

Writing info to SharePoint lists isn't the fastest operation in the world, so it's possible you could have the banner rotate, the request fire, and the user close the browser before the request was complete -- but in that case they would just wind up on the same slide they were at before (so just repeating the last step in the rare occassion where this happens).

like image 98
John-M Avatar answered Oct 16 '22 08:10

John-M